Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

Not working with .hbs View engine #8

Open
ytzvan opened this issue Aug 24, 2016 · 9 comments
Open

Not working with .hbs View engine #8

ytzvan opened this issue Aug 24, 2016 · 9 comments
Labels

Comments

@ytzvan
Copy link

ytzvan commented Aug 24, 2016

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
Copy link
Contributor

mxstbr commented Aug 24, 2016

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
Copy link
Author

ytzvan commented Aug 24, 2016

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

@mxstbr mxstbr closed this as completed Aug 24, 2016
@ytzvan
Copy link
Author

ytzvan commented Aug 24, 2016

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

@mxstbr mxstbr reopened this Aug 25, 2016
@mxstbr
Copy link
Contributor

mxstbr commented Aug 25, 2016

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

@ch-rs
Copy link

ch-rs commented Oct 7, 2016

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
Copy link

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
Copy link

ch-rs commented Dec 26, 2016

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
Copy link

masza commented Oct 27, 2018

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

@jennaprice
Copy link

jennaprice commented Nov 6, 2018

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


Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants