Node.js module for rendering beautiful emails with swig templates and email-friendly inline CSS using juice.
Inspired by niftylettuce/node-email-templates.
- Uses swig, which supports Django-inspired template inheritance.
- Uses juice, which takes an HTML
file and inlines all the
<link rel="stylesheet">
s and the<style>
s. - Uses swig-dummy-context which gives you the ability to generate dummy context from a template to aid in an email preview tool.
- URL rewrite support - you can provide a
urlRewriteFn
argument to rewrite your links.
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, generateDummy) {
var context = {
meatballCount: 9001,
};
render('meatball-sandwich.html', context, function(err, html) {
// send html email
});
generateDummy('meatball-sandwich.html', function(err, dummyContext) {
// dummyContext contains a context you can send to render, prepopulated
// with dummy values. you can use this if you're building an email
// preview tool.
});
});
- updated swig to 0.14.0
- updated juice to 0.4.0
- BREAKING CHANGE -
render
andgenerateDummy
no longer automatically append.html
to your template name to look it up. This means that if you before hadrender('meatball-sandwich')
you must change it torender('meatball-sandwich.html')
to work with 0.5.0. - fixed crash during cleanup
- updated juice to 0.3.2
- updated jsdom to 0.5.4