I am using the library with mustache.
Since the partials I use are shared among many pages, I have tried to keep them all together in a global object, writing something like the following:
const partials = {
header: "partials/header",
footer: "partials/footer",
/* ... */
}
/* ... */
app.get('/', function(req, res) {
res.render('index', { partials });
});
With this approach, the first call to the render function will change the values the partials global to the content of their respective files. This means that the call will work properly the first time, but fail from the second onward, since it will try to load a file with random html as a name.
I think this result is not what a user would expect, and if not changed it should at least be mentioned in the documentation (I didn't see any reference to it).
My current workaround is to call a function returning the literal object instead, but it feels like a dirty hack, suggestions for a better approach would be appreciated.
I am using the library with mustache.
Since the partials I use are shared among many pages, I have tried to keep them all together in a global object, writing something like the following:
With this approach, the first call to the render function will change the values the partials global to the content of their respective files. This means that the call will work properly the first time, but fail from the second onward, since it will try to load a file with random html as a name.
I think this result is not what a user would expect, and if not changed it should at least be mentioned in the documentation (I didn't see any reference to it).
My current workaround is to call a function returning the literal object instead, but it feels like a dirty hack, suggestions for a better approach would be appreciated.