You will learn
Learn about all the available conditions you can use to dynamically display a block, section, or custom-coded piece of content in an email template only to certain recipients. To learn how to use these conditions in your templates, head to How to show or hide template blocks based on dynamic variables.
Learn how to use conditional logic:
Where you can use conditionsWhere you can use conditions
You can use conditions:
- In show/hide logic, to dynamically display email template blocks or sections only to certain recipients.
- If you prefer not to write code, use the show/hide logic builder instead.
- Within if/else conditionals to write custom Django statements.
Tips for success
When building out show/hide conditions, pay attention to the details. Show/hide conditions are case-sensitive, and spelling must exactly match your profile or event data.
Also, make sure to consider all possible recipients for your email. For example, if you show a specific block only to residents of a certain state, cover all possible spellings of that state name (e.g., Massachusetts, massachusetts, mass, MA). Also take into consideration profiles who may not have the property set at all.
Once you’ve built the message and applied your conditions, preview the email using a variety of profiles to confirm that the message displays as you intended for all scenarios.
Condition structuresCondition structures
Conditions should include 1-3 elements, depending on your goal for the block and the data you’re using. The condition must at least include a variable (e.g., person|lookup:'Favorite Color'). It may also include a comparison function, like = (equals) or > (greater than) and a value, which specifies a specific property value to look for. Additionally, certain conditions begin with not, if you’d like the block to only appear for profiles that do not meet a condition.
The chart below contains a complete list of possible structures a show/hide condition can follow.
Sample condition | Show the block if... | Acceptable data types |
person|lookup:'Favorite Color' |
The |
Any |
not person|lookup:'Favorite Color' |
The |
Any |
person|lookup:'Favorite Color' == 'green' |
The |
Text, Number |
person|lookup:'Favorite Color' != 'green' |
The |
Text, Number |
person|lookup:'Age' > 20 |
The |
Number |
person|lookup:'Age' >= 20 |
The |
Number |
person|lookup:'Age' < 20 |
The |
Number |
person|lookup:'Age' <= 20 |
The |
Number |
'green' in person|lookup:'Favorite Colors' |
The property The property |
List, Text |
not 'green' in person|lookup:'Favorite Colors' |
The property The property |
List, Text |
Conditions for booleans
If you are referencing data stored as a boolean, you’ll need to use 1 and 0 rather than “true” and “false” in your show/hide condition definition. Do not surround the 1 or 0 in quotes. Use the sample conditions below as a template.
Sample condition | Show the block if... |
person|lookup:'VIP' == 1 |
The |
person|lookup:'VIP' == 0 |
The |
Conditions for booleans stored as text
If your true/false data is stored as text, not as a boolean, use the sample conditions for text properties above. If you aren’t sure, or if you are referencing a property that contains both booleans and text, you can use these structures to cover all scenarios. Include all spellings and capitalizations that are present in your data.
Sample condition | Show the block if... |
person|lookup:'VIP' == 1 or person|lookup:'VIP' == 'true' or person|lookup:'VIP' == 'True' |
The |
person|lookup:'VIP' == 0 or person|lookup:'VIP' == 'false' or person|lookup:'VIP' == 'False' |
The |
Build complex conditions
If you would like your block to display to people who meet multiple criteria, or if you have a complex use case, you can use multiple show/hide conditions for one block. To do so, connect a series of conditions with AND or OR. For example, if you want to display a block to anyone in Massachusetts, but Massachusetts is spelled differently on some profiles, you can use a condition like this:
person.location.region == 'Massachusetts' or person.location.region == 'massachusetts' or person.location.region == 'mass' or person.location.region == 'MA'
If you only want to show a block to people whose favorite color is green, and who are also VIPs, you can use a condition like this:
person|lookup:'Favorite Color' == 'green' and person|lookup:'VIP'== 1
Conditional statements and the inline text editorConditional statements and the inline text editor
When you add certain conditional statements to a text block, they may disappear from the inline text editor. The code is still present; it is just hidden. To view and edit conditional statements, open the text block's Source code field.
The following tags are only visible in a text block's Source code field:
- {% for ... %}
- {% endfor %}
- {% if ... %}
- {% elif ... %}
- {% else %}
- {% endif %}
- {% with ... %}
- {% endwith %}