Show or hide parts of an email based on what you know about each contact.
Normally every recipient of a campaign gets the same email. Merge tags like [CUSTOMER_FIRST_NAME] change a word. Personalised content blocks change a whole section.
One campaign can show a loyalty offer to your best customers and a welcome offer to everyone else, decided separately for each person as the email is sent.
Behind the scenes this uses Jinja (specifically Jinjava), a widely used templating syntax. You only need the four instructions in this article.
You need at least one custom attribute on your contacts. Custom attributes are the extra fields you define yourself, such as membershipTier, totalOrders or isSubscriber.
If you have not set these up yet, our step-by-step guide covers creating custom attributes and adding values to your contacts:
Personalised blocks are written in HTML, so they are added by inserting your own code rather than by dragging a block onto the canvas.
Open your campaign and insert your own code or template. Our step-by-step guide covers that:
Then wrap the content you want to show or hide, like this:
<!--{% if isSubscriber %}-->
<h2>Thanks for being a member!</h2>
<!--{% else %}-->
<h2>Join our rewards programme</h2>
<!--{% endif %}-->Save, and send yourself a test to check the layout still looks right.
<!-- and --> are required. Every instruction must sit inside an HTML comment exactly as shown. Without them the block will not work, and you will not see an error.| Instruction | What it does |
|---|---|
{% if ... %} | Starts a block. Shows what follows when the condition is true. |
{% elif ... %} | Optional. Checks another condition if the previous one was false. You can use several. |
{% else %} | Optional. Shown when none of the conditions above were true. |
{% endif %} | Ends the block. Always required. |
A longer example with several options:
<!--{% if tier == 'Gold' %}-->
<p>Your Gold benefits</p>
<!--{% elif tier == 'Silver' %}-->
<p>Your Silver benefits</p>
<!--{% else %}-->
<p>Upgrade and save</p>
<!--{% endif %}-->Blocks can also be placed inside one another, and you can use as many blocks as you like in one email.
Every custom attribute has a data type, chosen when you create it. The type decides which comparisons are available.
| Type | Use it for | What you can check |
|---|---|---|
| STRING | Text, such as names, tiers, cities | Has a value, equals, not equals, contains |
| INTEGER | Whole numbers, such as order count, points | Has a value, equals, greater / less than |
| DECIMAL | Numbers with decimals, such as spend, ratings | Has a value, equals, greater / less than |
| BOOLEAN | Yes / no, such as subscriber, VIP | Is true, is not true |
| DATE | Dates, such as signup date, renewal | Has a value, equals, before / after another date, before / after today |
| ARRAY | Lists, such as interests, tags | Has any items, contains a given item, list every item |
'yyyy-MM-dd', for example '2026-01-31', with the leading zeros. You can also compare against today, which always means the day the email is sent.| Write this | Means | Example |
|---|---|---|
attribute | Has a usable value | {% if tier %} |
not attribute | Is empty, missing or false | {% if not tier %} |
== | Equals | {% if tier == 'Gold' %} |
!= | Does not equal | {% if tier != 'Gold' %} |
> >= < <= | Number comparisons | {% if totalOrders > 3 %} |
in | Is contained in | {% if 'VIP' in tags %} |
> < on dates | Before / after a date | {% if optInDate > '2026-01-01' %} |
today | The day the email is sent | {% if renewalDate > today %} |
and / or | Combine two conditions | {% if isVip and totalOrders > 5 %} |
( ) | Group conditions | {% if (isVip or isStaff) and active %} |
Text values go in single quotes. Numbers do not.
<!-- Customers who have ordered more than three times -->
<!--{% if totalOrders > 3 %}--> ... <!--{% endif %}-->
<!-- Anyone who has spent over 500 -->
<!--{% if lifetimeSpend > 500 %}--> ... <!--{% endif %}-->
<!-- Contacts interested in running -->
<!--{% if 'running' in interests %}--> ... <!--{% endif %}-->
<!-- VIPs who have actually bought something -->
<!--{% if isVip and totalOrders > 0 %}--> ... <!--{% endif %}-->
<!-- Contacts with no tier set yet -->
<!--{% if not tier %}--> ... <!--{% endif %}-->
<!-- Anyone who opted in during 2026 or later -->
<!--{% if optInDate >= '2026-01-01' %}--> ... <!--{% endif %}-->
<!-- Renewals still in the future -->
<!--{% if renewalDate > today %}--> ... <!--{% endif %}-->For a list attribute you can print one line per item, instead of testing for a single one. Wrap the repeating part in {% for %} and {% endfor %}, and put the item where you want it using two curly braces.
<ul>
<!--{% for category in favoriteCategories %}-->
<li>{{ category }}</li>
<!--{% endfor %}-->
</ul>A contact whose list is Running, Cycling sees two bullets. A contact with an empty list sees none.
The word after for is a name you choose for “one item”. Use the same name inside the curly braces. The word after in must be your list attribute.
Pair it with a condition so contacts with nothing in their list still see something:
<!--{% if favoriteCategories %}-->
<ul>
<!--{% for category in favoriteCategories %}-->
<li>{{ category }}</li>
<!--{% endfor %}-->
</ul>
<!--{% else %}-->
<p>Browse our full range.</p>
<!--{% endif %}-->{{ category }} with curly braces. Square brackets such as [category] are merge tags for contact fields and will not work here.You do not need to worry about contacts with gaps in their data.
{% else %}.{% if totalOrders > 0 %} if you mean “has ordered at least once”.{% else %}. It is what contacts with missing data will see, and it keeps your email from having an empty gap.To check your conditions properly:
Use contacts whose values sit either side of your condition. For {% if totalOrders > 3 %}, use one contact with 1 order and one with 10.
| What you see | Most likely cause |
|---|---|
| The instruction text appears in the delivered email | The <!-- and --> are missing. Every instruction must be inside an HTML comment. |
| Everyone gets the same version | You are looking at a test send. Send to a real segment instead. |
| A section is missing entirely | An {% endif %} is missing, or the condition uses an attribute name that does not exist. |
| The condition is always false | The attribute has no value on those contacts, or a number is being compared with quotes around it. Write > 3, not > '3'. |
| A list prints nothing | The attribute is not set up as a list, or the contact’s list is empty. Check the attribute type on the contact record. |
| The list item name appears as text | The item is written with square brackets. Inside a loop use {{ item }} with curly braces. |
| The layout breaks | The block starts inside one table cell and ends in another. Wrap whole rows or whole sections. |
totalOrders and totalorders both work.if, elif, else and endif are supported. Loops and other Jinja features are not.[CUSTOMER_FIRST_NAME] to print a value. The {% ... %} instructions decide what to show, not what to print.'yyyy-MM-dd' with leading zeros. '2026-1-5' will not compare correctly.renewalDate > today is false on the day itself. Use >= if you mean “today or later”.