Skip to content

Nodejs Email templates

Chakradhar Jonagam edited this page Jun 25, 2015 · 2 revisions

install swig-email-templates

npm install swig-email-templates

create templates folder

mkdir templates

create welcome.html inside templates folder

welcome {{name}} 
your username is {{uname}}

Generate template using following code -- gen.js

var path = require('path')
  , emailTemplates = require('swig-email-templates')

var options = {
  root: path.join(__dirname, "templates"),
  // any other swig options allowed here
};
emailTemplates(options, function(err, render) {
  var context = {
    name: "name",
    uname: "debianmaster",
  };
  render('welcome.html', context, function(err, html, text) {
     console.log(html);
  });
});

node gen.js

Clone this wiki locally