I want to make session variables (or any others) usable in the views without repeating myself all over again.
I came up with this:
res.render('index', viewVariables(req, res, params, {});
And the viewVariables function:
function viewVariables(req, res, params, options) {
var returnObject = options || {locals:{}};
var locals = {
currentUser: req.currentUser ? req.currentUser : false
};
returnObject.locals = mergeObjects(locals, returnObject.locals, true);
return returnObject;
};
Thats not working in the latest expressjs version (different render method).
Is there a simpler or more elegent solution for that? (well I’m sure there is!)
Have you looked at dynamichelpers?
From the website:
Most of the times I like to make it a function instead. This way it will be only called when you call the function in your views.