I am trying to have multiple layout in a hapi application. I have 2 layout files: account, default
here is my view engine registration:
server.views({
engines: { html: require('handlebars') },
relativeTo: __dirname,
path: './views',
layoutPath: './views/layout',
layout: 'default'
//helpersPath: 'views/helpers',
//partialsPath: 'views/partials'
});
by default it grabs default, how do I force it for a specific file to show another layout?
I also tried adding it to the view call and it didnt work:
module.exports.index = function (request, reply) {
reply.view("home/index", {layout: 'account'});
}
The second argument to
reply.view()is thecontextobject. So what you're doing in your example is providing a context with alayoutproperty, that's why it doesn't work. Theoptionsshould be the third argument:reply.view(template, [context, [options]])If you have no
context, you can provide an empty object. This should work: