Last Updated: February 25, 2016
·
2.114K
· tralamazza

node-email-templates render hack

node-email-templates is a neat add-on for Nodemailer which allows you to store and render HTML/Text. The only problem is that it requires a specific folder with 3 files in it (html.ejs, text.ejs and style.css).
Here is a tip for dynamic rendering:

var emailTemplates = require('email-templates');

var et = emailTemplates('.', function(err) {
  et.render(
    tpl_arguments,
    '.',
    tpl_html,
    tpl_text,
    tpl_css,
    function(err, html, text) {
      console.log(html, text);
    });
});

Where tpl_html is the HTML template and so on...

Edit: Updated for email-templates 0.9