Logicify Contributes to Open Source: Mautic Advanced Templates Bundle

We recently released an open-source bundle for an email marketing tool, Mautic. It allows greater flexibility in email templates and makes life of active Mautic users easier. Glad to share it with everyone today!

Credits for the bundle to our CTO, Dmitry Berezovsky.

Mautic is an open-source marketing platform with a wide range of tools for meaningful, intelligent and personalized customer outreach. With its help, businesses can manage their contacts pool, segment it (manually or automatically) and interact with every segment per a custom-built outreach campaign. Recently, we integrated Mautic with our client’s custom e-commerce application. At Logicify, we also use Mautic for internal marketing purposes.

Mautic Email Templates

Under marketing campaigns, Mautic users receive templated emails created either with default or custom themes.

Mautic Default Email Themes
An email is composed of separate blocks arranged in a predefined order. If you have experience with MailChimp, you would definitely find this approach pretty familiar. To personalize the email, you can add variables to the templates, for instance:

Mautic Email Template with Variables

where {contactfield=firstname} is a variable; it is replaced with a person’s first name taken from the corresponding field of the Contact card once the email is sent.

Though templates allow some degree of personalization, they are not too flexible. Mautic prompts to create a separate template each time an email content changes, even if this is just one line of text. Of course, this becomes too tedious and time-consuming to add and manage separate template for each and every wording.

To address this issue, we wrote a bundle that allows to code a condition inside a Mautic email template to make it reusable. With the bundle, email content is customized depending on the information known about any contact.

Instead of creating tons of similar emails, just use one with conditions coded inside

About the Bundle

The bundle extends default Mautic email template capabilities with TWIG blocks. TWIG is an open-source template engine for PHP that allows to add conditions and cycles into email templates. Our bundle is distributed under MIT license, for free even for commercial purposes.

The bundle is installed easily and requires no configuration. So far, we tested bundle’s compatibility with

  • Mautic v2.14.2
  • PHP v7.1.23

Bundle Features

TWIG templates are added into emails between special tags:

{% TWIG_BLOCK %} 
Your template TWIG goes here....                                        
{% END_TWIG_BLOCK %}

The text between {% TWIG_BLOCK %} and {% END_TWIG_BLOCK %} in your emails will be treated as a TWIG template. Check out TWIG official documentation to familiarize yourself with syntax and capabilities.

Reusable TWIG snippets could be loaded from Dynamic Content entities, and the bundle functions and filters would help you avoid copy-pasting.
Here are a few use cases for the bundle.

Case 1: Personalize email per contact’s location

Say you'd like to make your email sound more “human” by adding an extra paragraph about weather in New York for people residing there. This is how the corresponding TWIG block in Mautic email template should look:

{% TWIG_BLOCK %}
    <p>Hi {{lead.firstname}},</p>
    {% if lead.city == 'New York' %}
        <p>What a great weather in New York this week!</p>
    {% endif %}

    <p>Main letter content goes here</p>        
{% END_TWIG_BLOCK %}

Case 2: Render structured data in an email

The bundle helped us implement the Abandoned Cart feature for one of our e-commerce apps. To remind a client they did not complete checkout, you could send out a Mautic-generated email with the list of abandoned cart items and a link to finalize the purchase.

You would need to build an integration with your e-commerce software, which pushes cart information into Mautic contact entity in the custom field cart. The cart information could be presented in JSON format as:

[
    {"sku": "123456", "name": "My cool product 1"},
    {"sku": "8574865", "name": "My cool product 2"}
]

To have the cart items rendered in an email, you could use the following TWIG block:

{% TWIG_BLOCK %} 
    {% set cart = lead.cart | json_decode %}     
    Your cart:
    <ul> 
    {% for item in cart %}
        <li>Item Name: {{ item.name }}</li>
    {% endfor %}
    </ul>             
{% END_TWIG_BLOCK %}

json_decode is a filter that converts string in JSON format into object.

Here is an email example from Shopify blog sent by Fab store to those customer who abandoned some items in their e-carts:

Example of Email with Abandoned Cart Item

Case 3: Write reusable code snippets

If you need similar blocks to be included into multiple emails, this makes sense to improve maintainability and keep common pieces in a single place. The bundle could help you leverage Dynamic Content entity with TWIG built-in function include().

For the previous example with abandoned cart items, you could turn the template for rendering a single item into a reusable snippet. To do this in Mautic, navigate to Components / Dynamic Content, then:

1.Create new entity with name email-cart-item.
2.Put the following into Content area:

<li>Sku: {{ item.sku }}, Name: {{ item.name }}.</li>

3.Update your email template with the following:

{% TWIG_BLOCK %} 
    {% set cart = lead.cart | json_decode %}     
    Your cart:
    <ul> 
    {% for item in cart %}
        {{ include('dc:email-cart-item') }}
    {% endfor %}
    </ul>             
{% END_TWIG_BLOCK %}

Notice prefix dc: which instructs template resolver to look for dynamic content instance.

Find more about the bundle on GitHub or ask us if you have any questions hi@logicify.com

Related articles

Tags