How to access sessions in Jade template

Share this post:

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:

res.locals.session = req.session;

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 🙂

Over 10 years in business.

Self-funded. No investors. No bullshit.

More than 3,000 customers worldwide.

Helpmonks - no bullshit customer engagement service

Growth starts with action

Empower your team and delight your customers.

Helpmonks - email management for small businesses