keystone-email
keystone-email copied to clipboard
Not working with .hbs View engine
I made this work using the example on the readme, but isn't working with a .hbs template. I installed the latest version of handlebars and express-handlebars. I'm using Keystone with handlebars view engine, however I can't feel comfortable with pug. Any workaround this ?
Did you specify the engine like so?
new Email('sometemplate.hbs', {
engine: require('handlebars'),
}).send();
(excuse any typos and the contrived example, am in the train)
@mxstbr I'll try that, but works well with ejs
@mxstbr still not working with Handlebars even when define the engine
Can you please show us the code you use? It's really hard to debug with just your explanations 😉
I had the same issue. I couldn't get the handlebars
or express-handlebars
modules to work. It's very possible I did something wrong (I'm no expert) but it seems like they're both missing the __express
function this module tries to assign in the getEngine util. The hbs
module has an __express
function but doesn't work either until you set the layout option to false.
Here's what works for me:
var Email = require('keystone-email');
var hbs = require('hbs');
templateLocals.layout = false;
new Email('./templates/emails/template.hbs', {
transport: 'mailgun',
engine: 'hbs',
})
.send(templateLocals, sendOptions, function (err, result) {
if (err) {
console.error('🤕 Mailgun test failed with error:\n', err);
} else {
console.log('📬 Successfully sent Mailgun test with result:\n', result);
}
});
Hey @Chrislah thank you for this helpful snippet.
Did you replace handlebars
with hbs
throughout your project or did you install hbs
strictly for this?
Is templateLocals
the renderOptions
argument from Email
?
Thanks again :)
I installed hbs
strictly for this and left the rest of Keystone using express-handlebars
, and yes, templateLocals
is the renderOptions
for Email.send
.
Happy to help (:
Why after more than 2 years we still must use these hack to use keystone-email with handlebars? 😮
Also having this problem. I need to fix this TODAY for a project at work. :(
I am getting
Error: Could not load engine ([object Object]). Please make sure you have installed the package in your project.```