keystone-email icon indicating copy to clipboard operation
keystone-email copied to clipboard

Not working with .hbs View engine

Open ytzvan opened this issue 8 years ago • 9 comments

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 ?

ytzvan avatar Aug 24 '16 22:08 ytzvan

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 avatar Aug 24 '16 22:08 mxstbr

@mxstbr I'll try that, but works well with ejs

ytzvan avatar Aug 24 '16 22:08 ytzvan

@mxstbr still not working with Handlebars even when define the engine

ytzvan avatar Aug 24 '16 23:08 ytzvan

Can you please show us the code you use? It's really hard to debug with just your explanations 😉

mxstbr avatar Aug 25 '16 00:08 mxstbr

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);
  }
});

ch-rs avatar Oct 07 '16 18:10 ch-rs

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 :)

peterpme avatar Dec 22 '16 15:12 peterpme

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 (:

ch-rs avatar Dec 26 '16 13:12 ch-rs

Why after more than 2 years we still must use these hack to use keystone-email with handlebars? 😮

masza avatar Oct 27 '18 00:10 masza

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.```


jennaprice avatar Nov 06 '18 15:11 jennaprice