I'm using 'lodash.template' like this
var compiled = _.template('<% _.forEach(image, function(image) { %><td><img src="https://s3.amazonaws.com/<%- image.image %>"</td><% }); %>');
I then generate emailHTML like this
res.render('templates/reset-password-email', {
name: name,
qc: qc,
images: compiled(qc),
appName: appName
}, function (err, template) {
if (err) {
console.log(err)
}
emailHTML = template;
callback(null, arr);
});
I then send email like this
var smtpTransport = nodemailer.createTransport(config.mailer.options);
var mailOptions = {
to: '[email protected]',
from: config.mailer.from,
subject: 'subjet',
attachments: [
{
path: filePath
}
],
html: emailHTML
};
smtpTransport.sendMail(mailOptions, function (err) {
if (err) {
console.log(err);
}
//done(err, 'done');
});
The problem that I'm having is that {{images}} which is the compiled lodash.template is being displayed as text instead of Html. For example the html below is being displayed as text not as html.
<td><img src="https://s3.amazonaws.com/8e580-b7e3-11e6-bea-c3c74fd.jpg"</td>
Can someone please help me figure out what I'm doing wrong. As always thank you for your help
You
<img>
tag is not closed. Add the closing>
and it should work find.