0

I am using express and jade in my nodejs application. On each route when rendering I need to access same object with config and localization object. It's working fine like this:

loadLoginPage: function(req, res) {
    res.render('login', {
        config: config,
        i18n: res
    });
}

But is there a way without rewriting {config:config,i18n:res} on each route? I tried to find how to solve this but without results.

  • I think this might be what you are looking for : http://stackoverflow.com/questions/16452123/how-to-create-global-variables-accessible-in-all-views-using-express-node-js – krakig Apr 12 '16 at 08:45

1 Answers1

0

You can use the app.locals object as the following (http://expressjs.com/en/api.html#app.locals) :

app.locals.config = "your config";
app.locals.localisation= "your localisation";

And then

loadLoginPage: function(req, res) {
    res.render('login');
}
krakig
  • 1,515
  • 1
  • 19
  • 33