A Drupal theme engine that extends Twig with MJML support for building responsive email templates. Write your email templates with full Twig capabilities — variables, includes, extends, blocks — and let MJML handle the responsive HTML output.
Requires Drupal 11.3.0 or later.
This module registers a custom theme engine named twig_mjml that plugs into Drupal's ThemeEngineInterface. Templates use the .html.twig.mjml extension and are processed in two stages:
{% include %}, {% extends %}, and {% block %} directivesNo Node.js is required at runtime. The MJML rendering is handled by a pre-built standalone binary provided by the MJML Render Binary package.
engine: twig_mjml and can have its own set of MJML templates while sharing common Twig partials via {% include %}.composer require drupal/mjml_render_engine
drush en mjml_render_engine
Create a theme that uses the twig_mjml engine:
# themes/custom/mail/mail.info.yml
name: 'Mail Theme'
type: theme
description: 'Email theme using MJML templates.'
core_version_requirement: ^11.3
engine: twig_mjml
base theme: false
Templates use the .html.twig.mjml extension:
{# themes/custom/mail/templates/email.html.twig.mjml #}
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-text>Hello {{ name }}</mj-text>
<mj-text>{{ message }}</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
Full Twig inheritance works — include both .html.twig and .html.twig.mjml files:
<mjml>
<mj-body>
{% include 'header.html.twig.mjml' %}
<mj-section>
<mj-column>
<mj-text>{{ content }}</mj-text>
</mj-column>
</mj-section>
{% include 'footer.html.twig.mjml' %}
</mj-body>
</mjml>
Override the MJML binary location in settings.php or settings.local.php:
$settings['mjml_render_bin.path'] = '/path/to/custom/mjml';
See the MJML Render Binary project for Docker commands to build custom MJML binaries for any version or platform.
ThemeEngineInterface introduced in 11.3)