Reputation: 9220
So, I get passing parameters to Jade files- piece of pie:
app.use('/myroute', function (req, res) {
res.render('myview', {somevar: 'Testing!'});
});
However- I have my layout.jade file that is implicitly read and rendered by Express, with no actual definition of route-view binding, and I'm trying to work out how to pass a variable into that template.
Any ideas? Cheers!
Ps- this is so that I can pass node's development/production variable to some front-end javascript that's being added on every page.
Upvotes: 1
Views: 3606
Reputation: 2157
You can also use #{settings.env}
in the jade template, which get the value from app.locals.settings.env
Upvotes: 5
Reputation: 9220
Ah, I worked out the answer. Set it as a local variable in express, as mentioned here: Express.js View "globals"
So, in app.js I included app.locals.env = app.settings.env;
and then in my layout.jade I added my javascript and simply used #{env}
inside the script to get the environment value.
Upvotes: 9