I am wondering if there is an easy way to access Express.js' req or session variables from within a Jade template without passing it in through the normal response.
Or is this the only way?
res.render('/', { session: req.session });
Jade, Vash, and Handlebars are template engines that can be used with Node. js.
Where is the session data stored? It depends on how you set up the express-session module. All solutions store the session id in a cookie, and keep the data server-side. The client will receive the session id in a cookie, and will send it along with every HTTP request.
Jade is a template engine for node. js and the default rendering engine for the Express web framework. It is a new, simplified language that compiles into HTML and is extremely useful for web developers. Jade is designed primarily for server-side templating in node.
Just add
app.use(express.cookieParser()); app.use(express.session({secret: '1234567890QWERTY'})); app.use(function(req,res,next){ res.locals.session = req.session; next(); });
Before
app.use(app.router);
and get your session in jade
p #{session}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With