How to use layout with handlebars?
timothykibler opened this issue ยท 3 comments
timothykibler commented
Used koa-generator (koa2 -e --hbs) to generate base code, it generates this:
app.use(views(__dirname + '/views', {
extension: 'hbs',
map: { hbs: 'handlebars' }
}));
By default this doesn't render the layout.hbs at all so I changed it to this:
app.use(views(__dirname + '/views', {
extension: 'hbs',
map: { hbs: 'handlebars' },
layout: 'layout'
}))
Adding layoutPath: __dirname + 'views/'
doesn't seem to work either.
Any ideas or am I doing something wrong here?
queckezz commented
layout
and layoutPath
is no option in handlebars. What are you trying to do? The following renders the file layout.hbs
as expected:
app.use(views(__dirname + '/views', {
extension: 'hbs',
map: { hbs: 'handlebars' }
}))
app.use(async function (ctx, next) {
await ctx.render('./layout')
})
timothykibler commented
I was trying to use the layout.hbs the same way that pug uses a layout.pug, which I realize now is handled differently in hbs. It looks like I should be using partials instead and I can accomplish what I want from your response in #74. Thanks.