Conditional logic reference for templates

read
Last updated at:

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 (classic editor) or How to show or hide template blocks based on dynamic variables (new editor)

Learn how to use conditional logic:

Where you can use conditions

You can use conditions: 

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 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 Favorite Color property is set (has any value)

Any

not person|lookup:'Favorite Color'

The Favorite Color property is not set (does not exist on the profile, or is empty)

Any

person|lookup:'Favorite Color' == 'green'

The Favorite Color property has the value green

Text, Number

person|lookup:'Favorite Color' != 'green'

The Favorite Color property does not have the value green

Text, Number

person|lookup:'Age' > 20

The Age property contains a number greater than 20

Number

person|lookup:'Age' >= 20

The Age property contains a number greater than or equal to 20

Number

person|lookup:'Age' < 20

The Age property contains a number less than 20

Number

person|lookup:'Age' <= 20

The Age property contains a number less than or equal to 20

Number

'green' in person|lookup:'Favorite Colors'

The property Favorite Colors contains a list, and green is one of the list items, OR

The property Favorite Colors contains text, and green exists anywhere in the text

List, Text

not 'green' in person|lookup:'Favorite Colors'

The property Favorite Colors contains a list, and green is not one of the list items, OR

The property Favorite Colors contains text, and green does not exist anywhere in the text

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 VIP property is set to the boolean value true

person|lookup:'VIP' == 0

The VIP property is set to the boolean value false

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 VIP property is set to the boolean value true or the strings true or True

person|lookup:'VIP' == 0 or person|lookup:'VIP' == 'false' or person|lookup:'VIP' == 'False'

The VIP property is set to the boolean value false or the strings false or False

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

Additional resources

x
Was this article helpful?
19 out of 30 found this helpful