Template does not render handlebar expressions
satyavh opened this issue · comments
I got server defined like this:
const MailQueue = new MailTime({
db, // MongoDB
type: 'server',
strategy: 'backup', // Transports will be used in round robin chain
transports,
from() {
// To pass spam-filters `from` field should be correctly set
// for each transport, check `transport` object for more options
return "Example <no-reply@example.com>";
},
concatEmails: false, // Concatenate emails to the same addressee
debug: true
});
And client like this:
const MailQueue = new MailTime({
db, // MongoDB
transports,
type: 'client',
debug: true
});
Now I"m sending an email like this:
MailQueue.sendMail({
to: 'example@email.com',
subject: 'You\'ve got an email!',
user: "John",
html: template,
template: "{{{html}}}",
baseUrl: host
})
And I load the template like this:
fs.readFile(process.env.PWD + app.get('templates') + '/email.html', (err, data) => {
if (err) { reject() };
resolve(data.toString());
});
The email sends fine, but the handlebars expressions in the template are not replaced with the opts.
What am I doing wrong?
Hello @satyavh ,
- What do you mean by
handlebar expressions
, could you provide an example from used template? - Try this:
MailQueue.sendMail({
to: 'example@email.com',
subject: 'You\'ve got an email!',
user: "John",
template: template, // <- Template with Mustache-like placeholders, here you can use options used in `sendMail`, like: to, subject, user, and baseUrl
baseUrl: host
});
Sorry, I mean Mustache-like placeholders!
Here's a part that does not render
<p>Hi {{user}}, </p>
It return like this in the email Hi {{user}}
Try my example (from above):
MailQueue.sendMail({
to: 'example@email.com',
subject: 'You\'ve got an email!',
user: "John",
template: template, // <- Template with Mustache-like placeholders, here you can use options used in `sendMail`, like: to, subject, user, and baseUrl
baseUrl: host
});
Sorry, it doesn't work.
I'm now parsing my templates with https://www.npmjs.com/package/mustache
You might want to use that too.
@satyavh does it work if you use it as global template?
const MailQueue = new MailTime({
db, // MongoDB
type: 'server',
strategy: 'backup', // Transports will be used in round robin chain
transports,
from() {
// To pass spam-filters `from` field should be correctly set
// for each transport, check `transport` object for more options
return "Example <no-reply@example.com>";
},
concatEmails: false, // Concatenate emails to the same addressee
template: 'Hi {{user}}',
debug: true
});
and then send:
MailQueue.sendMail({
to: 'example@email.com',
subject: 'You\'ve got an email!',
user: "John",
baseUrl: host
})
Yes that works
According to this line, next code should work too:
const MailQueue = new MailTime({
db, // MongoDB
type: 'server',
strategy: 'backup', // Transports will be used in round robin chain
transports,
from() {
// To pass spam-filters `from` field should be correctly set
// for each transport, check `transport` object for more options
return "Example <no-reply@example.com>";
},
concatEmails: false, // Concatenate emails to the same addressee
debug: true
});
MailQueue.sendMail({
to: 'example@email.com',
subject: 'You\'ve got an email!',
user: "John",
baseUrl: host,
html: '<p>Hi {{user}}</p>',
template: '{{{html}}}'
})
Is it the same as in your initial message?
No that does not work, the email now shows:
Hi {{user}}
Marked as [bug], thank you for reporting this.
Going to double check it.