I started using node.js + express combo quite recently, and I came across the need to use dynamicHelpers not only in my views, but also in the route settings (routes / index.js in the default express configuration). Should I use several different templates?
app.js
app.dynamicHelpers({
translate : function(req, res) {
return translate;
},
language : function(req, res) {
return req.session.language || "en";
},
});
Below I would like to have convenient access to what I installed for my dynamic assistants, because, in my opinion, this is the same context .. so why install it twice?
var routes = {};
routes.index = function(req, res) {
res.render('index', {
title : 'My webpage',
categories : categoryPositions,
referrer : req.header("Referrer"),
languages : ["pl", "en", "de"],
<----- here I would like to use my dynamicHelpers (for example translate)
})
};
I know that I can transfer my data in different ways, but I do not want to repeat my code and want to set up the general context only once and as cleanly as polssible. I welcome any criticism and good advice!