keystonejs / keystone-email

⚠️ Archived - Legacy email helper for KeystoneJS Apps
MIT License
29 stars 40 forks source link

Not working with .hbs View engine #8

Open ytzvan opened 8 years ago

ytzvan commented 8 years ago

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 ?

mxstbr commented 8 years ago

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)

ytzvan commented 8 years ago

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

ytzvan commented 8 years ago

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

mxstbr commented 8 years ago

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

ch-rs commented 7 years ago

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);
  }
});
peterpme commented 7 years ago

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

ch-rs commented 7 years ago

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

masza commented 5 years ago

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

jennaprice commented 5 years ago

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