Search code examples
node.jshandlebars.jsexpress-handlebars

Specify layout in res.render() while also feeding it data


I have this code:

res.status(200).render('body_loggedin', usernameDocs[0]);

to render the data from usernamedocs[0] into the 'body_loggedin' view but I don't want it to to have the main layout. Every answer to similar questions doesn't address this.

Thank you for any help!


Solution

  • You can pass an options object, specifying the layout:

    res.render('foo-template', { layout: 'foo', data: 'bar' })