Multiple layouts with Handlebars and ExpressJS?

You should be able to pass in the layout from your route/controller when you call the render method.

router.get('/', function(req, res) {
    res.render('home', {layout: 'viewBLayout.hbs'});
});

I am pretty sure jade will let you switch layouts from inside the template but I don't know if you can do that with handlebars.


If you use express-hbs, you can specify a layout in the template with a comment like:

{{!< layout}}

Alternatively, you can try exphbs. It also supports layout comments and multiple layouts can be nested. (Disclaimer: I wrote it.)