Express 4 handlebars render without layout Express 4 handlebars render without layout express express

Express 4 handlebars render without layout


Assuming you are using express-handlebars you can specify a different layout from your route/controller when you call the render method. To get rid of the layout altogether you can set the layout to false.

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

https://github.com/ericf/express-handlebars#layouts


It should be clear, when you have data to render, that the layout should be merely an extra property of such data

var data = {    layout: false,     var1: var1,    var2: var2};res.render('home', data); 


If you don't wish to give layout, you have to specify as layout: false . Otherwise app will crash. You can configure as follow, if you need.

app.get('/', (req, res, next) => {    res.render('shop', { title: 'My Shop', layout: false })});

For more congiguration of express-handlebars