Mailjet's template language allows you to push the boundaries of the personalisation of an email.
More than just substitutions of a text, it lets you leverage conditions, loops, functions and multiple data sources.
With the Mailjet's template language for transactional messages, designing and building dynamic emails, that can highly adapt to your recipients' profiles, has never been easier.
Mailjet Template language is available for transactional messages only. As Mailjet templating language is following a syntax close to the one used by the most popular template languages, such as Jinja2 or Twig, it can be already familiar to you.
Go beyond simple personalization tags by adding logic into your email to include/remove sections of the delivered message.
Additionally, Mailjet's Template API allows you to store your templates on the Mailjet system. There is no need to provide the whole content of your message at each call to the Send API anymore, just use your predefined template.
You can create your template, leveraging our template language, in multiple ways: either through Passport - our drag and drop email design tool - MJML - the open source responsive email framework we created - or even with simple HTML.
The syntax is:
<html>
<body>
{% if data:age > 45 %}
<ul>
<li>{{data:age}}</li>
</ul>
{% endif %}
</body>
</html>MJML and templating language, a superhero duo
Today, flexibility and personalization are a must-have in the email industry. Transactional emails imply more and more complex business logic, and one can often struggle trying to juggle a lot of different templates, when they could just have one personalized email that adapts to several use cases. Having a separate template for men and another one for women, or creating specific campaigns to recommend different things based on your customer's previous purchases is not viable.
It is in this kind of situations that a templating language comes in handy. OK, let’s be a bit naive and accept that you could write your own. But to be able to implement a tokenizer and a grammar, you need to have a good knowledge in the field and, at the end of the day, you might just be reinventing the wheel when you could have been focusing on your core business instead... You could instead use nice libraries such as Handlebars, Jinja or Twig, but then you’ll still need to write or host a dedicated service to handle the templating processing.
So, let’s recap: MJML for producing responsive HTML emails without effort, plus a templating language to bring them to life with conditional blocks and variables. This combo can change your life as a developer.
But, enough words, you’ll definitely want some action. You will find here four tutorials that will explain you step by step how to solve very common issues in template creation.
- How to create an e-receipt email template
- How to create a welcome email template
- How to create an abandoned cart email template
- How to create an digest email template
You can find some use case samples on Github
- All in one transactional : one template rules all your simple transactional messages. Make it easy to manage a single canvas for all your messages
- Mailjet Air Electronic ticket : depending on the destination, the seat class and booking of a car to the airport, the layout changes and offers specific call to actions
- Question / Answers / Comment notifications : alerts for new question, comment and answer (Quandora like) with specific call to action depending on the alerts
- All in one Ecommerce : one template to support all your order, payment, shipping... notifications.
- White label : handle several brands with one transactional template
- RSS to email : pull a RSS feed and send it by email (simple loop sample)
- Product list : simple product list (loop sample)
- Product list in zigzag : product list with alternative image side (loop sample)
- Ecommerce receipt : list of product purchased and total price of purchase (loop sample)