Achieve a high level of personalization in Mautic using Twig Templates.
if/else
block to check if contact.firstname
exists.default
filter as a shorthand to provide a fallback value directly within the output {{ }}
tags.{twigtemplate=TEMPLATE_NAME}
token, replacing TEMPLATE_NAME
with the exact name of the Twig Template you created and saved in Mautic.
Example: Tier-Based Promotional Offers
Imagine you want to show different offers to contacts based on their membership level, stored in a custom field called membership_tier
. You could create separate Twig Templates for each offer (e.g., save templates named Gold Member Offer
, Silver Member Offer
, Standard Welcome Offer
).
Then, in your main email or landing page template, you can use conditional logic to insert the correct offer template based on the contact’s membership_tier
field:
Gold Member Offer
), and the change automatically applies everywhere it’s inserted. Just ensure the template names you reference exactly match those saved in your Mautic Twig Templates list.
{twigtemplate=...}
token to dynamically choose which template to insert. This simplifies your main template when dealing with variations based on contact data.
Example: Simplified Tier-Based Offers
Following the previous example, if you named your saved templates consistently based on the membership tier (e.g., offer-gold
, offer-silver
, offer-standard
), you could replace the if/elseif/else
block with a single dynamic token:
{{ contact.membership_tier|default('standard') }}
) to get the final template name (like offer-gold
). Then, it inserts the content of the matching saved Twig Template.
Ensure the generated names exactly match your saved Twig Template names.