Helpmonks Logo

How to access sessions in Jade template

How to access sessions in Jade template

Accessing sessions in your Jade template is not straight forward, as in “it just works”. In order to do so, you have to use the Middleware. In short put the following in your app.js/server.js:

[code]app.use(function(req,res,next){
res.locals.session = req.session;
next();
});
[/code]

Note: Make sure you insert the above before app.use(app.router);

Once done you are now able to access your sessions with #{session.myvar} in your Jade templates.

Enjoy 🙂

Nitai

Nitai

Founder & CEO of Helpmonks. Serial Entrepreneur. Getting things done.