
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
mjml-handlebars
Advanced tools
Use MJML to pregenerate your emails, then Handlebars with i18n support to generate your final emails (html and text).
BONUS: Live preview your templates with sample variables for all your languages.
npm install mjml-handlebars
yarn add mjml-handlebars
Add this scripts to your package.json
"emails": "mjml-handlebars",
Use this if you are using custom root folder and dotenv
"emails": "node -r dotenv/config node_modules/.bin/mjml-handlebars",
npm install -D npm-run-all @compodoc/live-server nodemon
yarn add -D npm-run-all @compodoc/live-server nodemon
Additional package.json scripts:
"emails:dev": "run-p emails:watch emails:preview",
"emails:watch": "nodemon --exec 'npm run emails' -e mjml -i emails/output",
"emails:preview": "live-server -q emails/preview"
Add emails/preview to your .gitignore
Generate an emails/templates folder, add your mjml templates there. If your run the emails script, the emails/output and emails/preview folders will be generated with the compiled assets.
By default it uses {cwd}/emails as root folder, can be changed with MJML_HANDLEBARS_ROOT environment variable.
Run
emails:devto watch for changes and a live server preview
To generate the final email, the precompiled version of the handlebars email will be used to improve performance. Example:
import { generateEmail } from 'mjml-handlebars'
const { html, text, subject } = generateEmail(
'welcome',
{
email: 'john@gmail.com',
items: [{ name: 'item1' }, { name: 'item2' }, { name: 'item3' }],
showButton: true,
disclaimer: 'This is the disclaimer',
},
'de', // Language
'en' // Optional fallback Language
)
There are 4 required comment blocks (only available for main templates, not partials):
There is support for logical operators, taken from here
Example template:
<mjml>
<mj-head>
<mj-include path="./partials/head.mjml" />
</mj-head>
<mj-body>
<mj-include path="./partials/header.mjml" />
<mj-section mj-class="main">
<mj-column>
<mj-text mj-class="title">
{{__ "greetings" email=email}}
</mj-text>
<mj-text>
{{__ "welcome"}}
</mj-text>
<mj-raw>{{#if showButton}}</mj-raw>
<mj-button href="#">
Go to my account
</mj-button>
<mj-raw>{{/if}}</mj-raw>
<mj-raw>{{#each items}}</mj-raw>
<mj-text>Item: <b>{{this.name}}</b></mj-text>
<mj-raw>{{/each}}</mj-raw>
<mj-text>
{{#if (ne type 'show') }}
{{disclaimer}}
{{else}}
no disclaimer
{{/if}}
</mj-text>
</mj-column>
</mj-section>
<mj-include path="./partials/footer.mjml" />
</mj-body>
</mjml>
<!-- text
{{__ "greetings" email=email}}
{{__ "welcome"}}
-->
<!-- subject
{{__ "greetings" email=email}}
-->
<!-- vars
email: john@gmail.com
items:
- name: item1
- name: item2
- name: item3
showButton: true
type: 'show'
# disclaimer: 'This is the disclaimer'
-->
<!-- i18n
en:
greetings: hello {{email}}
welcome: Welcome to my company
es:
greetings: hola {{email}}
welcome: Bienvenido a mi empresa
-->
See a working example project at /example.
MIT
FAQs
Use MJML with Handlebars with i18n support and text-mode
The npm package mjml-handlebars receives a total of 46 weekly downloads. As such, mjml-handlebars popularity was classified as not popular.
We found that mjml-handlebars demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.