Nimiq Email Template and Email Generator

Sample Email Template

This repository provides a default template that can be compiled to html emails in the Nimiq style. The build process is based on gulp-email-workflow by Ire Aderinokun. New emails can be either generated by the template engine of this repository or by using a prebuilt MailChimp compatible template.

Using MailChimp

This repository includes an email template enriched with MailChimp Templating Tags and Merge Tags. To use it with MailChimp, just copy the prebuilt mailchimp.html to MailChimp as a new template. No additional setup is required.

Using the Template Engine

Install dependencies

npm install

Building

gulp

The compiled emails will be in the build/ directory.

Template Engine

Nunjucks is used for compiling template files to HTML.

Templates are stored in src/templates/ and partials in src/templates/partials. To create a template, create a file in the templates directory with the .nunjucks file extension.

See https://mozilla.github.io/nunjucks/templating.html for the whole Nunjucks templating documentation. Here are some options of particular interest:

{% include "partials/PARTIAL_FILE_NAME.nunjucks" %}

Includes a partial into the mail.

{% extends "main.nunjucks" %}

Creates a template based on a parent template.

{% block CUSTOM_BLOCK_NAME %}{% endblock %}

Defines a block of dynamic content to be replaced. To specify the content of a block, the child template can define the same block with the specific content.

{% macro macroName(param1, param2='', ...) %}{% endmacro %}

Defines a macro that generates content which can be used as ``.

Default Template

Main Layout

The main layout and design is defined in /templates/main.nunjucks. It provides the following hooks for your content:

{% block CONTENT %}{% endblock %}

For the main content of your email.

{% block SUBSCRIPTION_INFO %}{% endblock %}

For providing the recipient with information why he is receiving the email and how he can unsubscribe.

{% block FOOTER %}{% endblock %}

A footer on the very bottom on the email. For example for providing a copyright notice.

Predefined Macros

Useful macros are predefined in /templates/partials/macros.nunjucks:


To create a heading.


To create a plain text paragraph.


To create a paragraph consisting of a link.


To insert an inline link within a paragraph that can go along other plain text.

If you want to to use a html string as input to a macro, append a | safe to the argument.

Creating New Emails Based on the Default Template

To create an email based on the default template, create a new file in the src/emails/ directory with the .nunjucks file extension.

Inherit from the the main template by using the following syntax -

{% extends "main.nunjucks" %}

Import the predefined macros by -

{% from "../templates/partials/macros.nunjucks" import paragraph, title, paragraphLink, inlineLink %}

Now you’re ready to define the content of your email. To see how everything plays together, have a look at /emails/example-mail.nunjucks.

Creating Your Own Templates or Changing the Default Template

As there is a myriad of different mail clients out there and many are based on outdated or restricted rendering engines, special rules need to be followed when creating email templates.

The following links are a good starting point:

Some key points to take away are: