SyntaxError: Invalid regular expression: missing / in file [.../report.html].
zeg-io opened this issue · comments
I've set a proof of concept project, which properly renders HTML and sends an email, which it does,
Then I attempted to use the Handlebars {{#each objects}} directive in the template, and now I'm getting the following:
SyntaxError: Invalid regular expression: missing / in file [.../report.html].
where ... [.../report.html] is the raw html template.
I'm putting handlebar variables in it which renders non-repeated variables just fine, I'm trying to allow it to use an array and repeat a section of the email.
var EmailTemplates = require('swig-email-templates'),
nodemailer = require('nodemailer'),
handlebars = require('express-handlebars'),
hbs = require('nodemailer-express-handlebars');
var transporter = nodemailer.createTransport('smtp://smtp.advantix.local');
var viewEngine = handlebars.create({});
transporter.use('compile', hbs({
viewEngine: viewEngine,
viewPath: path.resolve(__dirname, 'templates/views'),
extName: '.hb'
}));
var templates = new EmailTemplates({
root: path.join(__dirname, 'templates/src'),
juice: {
webResources: {
images: 9 // Inline images under 8kB
}
}
});
var context = {
coverImage: 'http://i.istockimg.com/file_thumbview_approve/64115753/6/stock-illustration-64115753-hands-holding-smartphone-vector-.jpg',
coverBackground: '#4091BE',
devices: [
{ phoneNumber: '(555) 555.5555', type: 'iPhone', price: '$909.09', chartPath: '' },
{ phoneNumber: '(333) 333.3333', type: 'Monitor Phone', price: '$33.33', chartPath: '' }
]
};
templates.render('./report.html', context, function(err, html, text) {
if (err) {
console.log(err);
} else {
// Send email
transporter.sendMail({
from: 'noreply@domain.com',
to: 'recipient@domain.com',
subject: 'Mobility Report',
html: html,
text: text
});
}
});
Any idea where I'm going wrong?
I'm not sure why you're using swig-email-templates if you are using Handlebars templates. swig-email-templates uses the Swig templating engine which has different syntax to Handlebars.