Closed sean-hill closed 6 years ago
I think it might have to do with handlebars
vs hbs
extension. I remember a similar issue with nunjucks engine in the past. Unsure though, have you tried renaming your file extensions to .handlebars
?
https://github.com/tj/consolidate.js/blob/master/lib/consolidate.js#L171-L189
I believe I see exactly what issue is, we have to do a line similar to https://github.com/tj/consolidate.js/blob/master/lib/consolidate.js#L1610.
exports.hbs = fromStringRenderer('handlebars');
Want to test this out locally and submit a pull request to the consolidate repo?
Basically you'd do this:
yarn
and then npm link
.npm install
, and then npm link
.npm link consolidate
npm link email-templates
, and then run it againcc @sean-hill @polonel
Just to let you know I also have this issue. I've forked the repos and done the edit to consolidate, but still it does not work for me. I'm getting a "Cannot find module 'handlebars'" error, but I might not have managed my dependencies correctly. I will keep working on it but wanted you to know this really breaks my email system since all of my templates are using handlebars.
npm install handlebars
in the root of your project?
Yes, handlebars has been installed in the root of the project but still not working. But I found a workaround here:
https://github.com/niftylettuce/email-templates/issues/149
Renaming my template files with .handlebars
extensions and adding the following to my code before doing a renderAll()
works:
// Override consolidate's handlebars instance email.config.views.options.engineSource.requires.handlebars = Handlebars;
Sorry I don't have more time to pursue this to get the .hbs extensions working, but thanks for the response!
I had the same error. I added mapping and had no further issues:
const email = new Email({
views: {
root: path.resolve(__dirname, `templates`),
options: {
extension: 'hbs',
map: {
'hbs': 'handlebars'
}
}
}
})
Should be resolved now, try v3.4.0. I've added the default mapping to of hbs to handlebars per the PR in #284.
I'm not sure if I should open a new issue just to say that you must also map 'njk' to nunjucks:
views: {
options: {
extension: 'njk',
map: {
'njk': 'nunjucks'
}
}
}
It would be nice if you could also add it as a default.
@petersaints I've added this in v3.5.1 of email-templates. The only thing you will need to do is specify the views.options.extension: 'njk'
option. The mapping of njk: 'nunjucks'
has been added as a default similar to hbs => handlebars above. npm install email-templates@latest
or yarn add email-templates@latest
. thanks for request.
Hey there, I'm using
handlebars
as my templating engine. I have ahtml.hbs
file in my project and havehandlebars
installed locally in my project. I have my options setup like this:But I'm receiving a:
error when trying to render the template. Any suggestions?