Handlebars helpers not being registered
kingjerod opened this issue · 5 comments
Seems like the helpers are not being registered in handlebars. Code:
index.js:
app.use(views(viewPath, {
map: {hbs: 'handlebars'},
options: {
helpers: {
hello: (name) => {
return "Hello " + name;
}
}
}
}));
index.hbs:
<html>
<head><title>View Test</title></head>
<body>
<div>{{hello "Jerod"}}</div>
</body>
</html>
When accessing the page, it throws Error: Missing helper: "hello"
Regular handlebars templates work fine, I have tested it without helpers.
https://github.com/queckezz/koa-views/blob/master/test/index.js#L132-L149
This test is passing. Can you compare it to yours?
So I'm starting to think there is some strange library conflict going on. I tried to create a new project to narrow down where the problem is coming from, but it works fine when I do that. It still doesn't work with my main project where I have a lot of other libraries installed, and I can't go about removing things piece by piece until I figure out which one is the culprit. I did create a repo so if somebody really wants to get the bottom of it, it has everything to reproduce the problem. I also copied the exact error that happens.
Try bumping your version from 5.0.2
to 5.2.0
. View specific options are only supported since 5.1.0
. See 1c0914c
That appears to be the problem, upgrading fixed it. When I do npm install koa-views@next
it installs 5.0.2 :(
Aaah my bad, I'll update the tag!