Add Display Conditions to an Email

Prev Next

Display condition parameters help you dynamically change the content of your email that is displayed to the users based on whether they meet a specified condition. 

This guide explains the following concepts:

The syntax of tags used in the conditions differs from that of dynamic content tags used for personalizations.  Unlike the dynamic content tag, the tags are annotated with {% and %}. Every condition tag should have a beginning that has the condition itself, and an ending to specify where the condition ends. A full condition syntax with some example attributes is as follows:

{% if name == "Jon" %}

    // This block will be displayed if the user name is Jon

{% elif name == "Jane" %}    

    // This block will be displayed if the user name is Jane

{% elif name == "Jack" or name == "Pam" %}

    // This block will be displayed if the user name is Jack or Pam

{% else %}

    // if all else is not true

{% endif %}

Your title goes here
You can use Default and Custom Attributes in both Email and Architect email campaigns. Meanwhile, you can use Cart & Browsed items, event parameters, and coupons only in Architect email campaigns.

The display conditions feature is not supported when the synchronized module is enabled.


Syntax guidelines for display conditions

You can create your display conditions in alignment with the following syntax guidelines:

  • Only UTF8 quotation marks are supported in the display conditions.
    • Example for a supported quote: {% if name|lower == "jon" %}
    • Example for an unsupported quote: {% if name|lower == “jon” %}
  • There must be a space between the operator and the value. Otherwise, the display condition cannot be executed. 
    • Example for a supported syntax: {% if name|lower == "jon" %}
    • Example for an unsupported syntax: {% if name|lower ==“jon” %}
  • Dynamic attributes added inside the display condition must be without {{ }} brackets. 
    • Example for a supported syntax: {% if name == "jon" %}
    • Example for an unsupported syntax: {% if {{name}} ==“jon” %}

If there are any syntax errors, a red toaster notification will be displayed. In this case, you should check and fix the syntax.

Your title goes here
If there are custom attributes inside the conditions, they should have c_ at the beginning and have underscores between the words. Also, you should check the capital letters if they are the same as in the database. E.g. c_country_code, c_travel_dates.

Examples of different variable types

Below are some examples of integer, string, array string, float, and boolean variables.

Only attributes of the following types can be used in display conditions: Integer, string, float, and boolean.

Integers

{% if age > 25 %}
   // This block will be displayed if user age is older than 25
{% endif %}

% if age >= 25 %}
   // This block will be displayed if user age is older than or equal to 25
{% endif %}

{% if age == 25 %}
    // This block will be displayed if user age is 25
{% endif %}

{% if age < 25 %}
   // This block will be displayed if user age less than 25
{% endif %}

{% if age <= 25 %}
    // This block will be displayed if user age less than or equal 25
{% endif %}

Strings

{% if name == "Jon" %}
    // This block will be displayed if user name is Jon
{% endif %}

{% if name != "Jon" %}
   // This block will be displayed if user name is not Jon
{% endif %}

{% if name|lower == "jon" %}

    // This block will be displayed if user name is Jon, JON, JOn, joN

    // For string matches, it is a best practice to always compare against a lowered string

{% endif %}

{% if "high" in field|lower %}

    // This block will be displayed if field contains text "high"

{% endif %}

{% if "high" in field|lower %}

    // This block will be displayed if field contains text "high"

{% else %}

    // Else block

{% endif %}

You can use in condition in your emails as the “it contains” function. Thus, you can search for part of the text or value inside the attributes like the following use cases.

Your title goes here
You can use this lower tag in your display conditions with the following syntax: {%if "jo" in name|lower %} . The lower tag enables a specific part to be case-insensitive and allows you to search for that specific part inside the attribute.

{%if "jo" in name|lower %}

//This block will be displayed if name attribute contains text "jo" 

{% endif %}

{%if "skirt" in cart_abandoned %}

//This block will be displayed if user has item with "skirt" in their cart

{% endif %}

Array String

You can create a condition as follows for an array string attribute with "red", "orange", and "blue" values.

{% if "red" in c_favorite_color %}
// This block will be displayed if one of the user’s favorite colors is red.
{% endif %}

Floats

{% if c_cart_amount == 10.0 %}

    // This block will be displayed if cart amount is 10.0

{% endif %}

{% if c_cart_amount >= 10.0 and c_cart_amount < 11.0 %}

    // This block will be displayed if cart amount is between 10 and 11

{% endif %}

{% if c_cart_amount > 10.0 %}

    // This block will be displayed if cart amount is bigger than 10.0

{% endif %}

{% if c_cart_amount < 10.0 %}

    // This block will be displayed if cart amount is less than 10.0

{% endif %}

Your title goes here
When your field is a floating point number, your condition should also be a floating point number. For example, if you want to create a display condition when your field is $10 and set your field as == 10, the renderer will ignore it due to the type mismatch in case the field comes as a floating point number. For this reason, your condition should be as follows: {% if c_cart_amount == 10.0 %}. If you want to ignore the floating number and want your condition to work based on the left side of the number (10), then your condition should be as follows: {% if c_cart_amount >= 10.0 and c_cart_amount < 11.0 %}. In this case, any floating number between 10 and 11 will meet the condition. 

Boolean

In the case of c_is_vip_user = true, you can use the following conditions to check if a user is VIP or not:

{%if c_is_vip_user == true %}

  // This block will be displayed if user is_vip_user

{% endif %}

{%if c_is_vip_user != true %}

  // This block will be displayed if user not is_vip_user

{% endif %}

Boolean condition also works with 1 (true) and 0 (false). In the case of is_vip_user = 1, the syntax will be as follows:

{%if c_is_vip_user == 1 %}

  // This block will be displayed if user is_vip_user

{% endif %}

{%if c_is_vip_user == 0 %}

  // This block will be displayed if user not is_vip_user

{% endif %}

Create display conditions

You can create custom display conditions or use one of the pre-built conditions.

To set your conditions, follow these steps:

1. Select a container, structure, or stripe within your email’s design in Drag&Drop editor.

2. Go to the Conditions tab in the structure settings.

3. Toggle on the Apply Display Conditions button to select Demographics or Custom.

Demographics

4. Select a pre-built display condition from the list.

5. Click the Edit button to edit the selected pre-built display condition if you want to change it based on your target audience.

Below you can see the list of pre-built conditions along with their codes before and after modules.

NameDescriptionCode before moduleCode after module
LanguageUsers who are in English will see the banner{% if language == "en_US" %}{% endif %}
CountryOnly people who live in Australia will see the banner{% if location == "Australia" %}{% endif %}
Country & CityOnly people who are located in that country and city{% if country == "United Kingdom" and city == "London" %}{% endif %}
Age (Less than operator)Users whose age is less than 18{% if age < 18 %}{% endif %}
Age (Equal and greater than operator)Users whose age is equal to or greater than 25{% if age >= 25 %}{% endif %}
Age (Greater than & less than operators)Users whose age is between 18 and 25{% if age > 18 and age < 25 %}{% endif %}
GenderUsers whose gender is Female{% if gender == "Female" %}{% endif %}
StateUsers whose state is one of the following. c_state is a custom attribute. Use this condition if you have the attribute with the same naming.{% if c_state == "VIC" or c_state == "NSW" or c_state == "QLD" %}{% endif %}
VIP UserUsers who are VIP users for that brand. is_vip_user = true. is_vip_user is a custom attribute. Use this condition if you have the attribute with the same naming.{% if c_is_vip_user %}{% endif %}
Membership TypeUsers who belong to gold or silver membership type. is_gold_member = true, is_silver_member = true. These are custom attributes. Use this condition if you have the attribute with the same naming.{% if c_is_gold_user or c_is_silver_user %}{% endif %}

Custom

6. Enter the condition name, description, before and after statements. You can refer to Different Variable Types and Advanced Use Cases to create your conditions.

Your title goes here
(!) operator is supported with the following case or {% if field == false %}.
In each statement, you should use only one field name.
Single equal operator (=) is not supported in number type attributes.

When you are using cart abandonment or browse abandonment templates, you can see the predefined display conditions based on the use cases. Each row of the email template has different display conditions.

You can now use expressions inside the display conditions to define more flexible visibility rules for your email content. Instead of selecting a dynamic attribute, you can write an expression directly in the condition. Below is an example for this case.

{% if exp_age == 25 %}

   This content will be shown only if the expression is true.

{% endif %}

This allows you to dynamically control which blocks of content appear to each recipient based on your own logic.

Advanced use cases

You can combine display conditions with dynamic content, and personalize emails inside the same campaign without creating additional campaigns. 

You can use conditions with dynamic variables to segment your customers according to their information such as subscription package, age, and country.

Below you can see some examples of advanced use cases:

Show the trend products in the customer's age range

{% if age >= 18  and age < 25 %}

What a beautiful age is {{age|yours}}, here are the products you might like

//Teen products will be displayed with users age if it is between 18-25. "Yours" is used for fallback.

{% elif age >= 25  and age < 40 %}

What a beautiful age is {{age|yours}}, here are the products you might like

//Middle age products will be displayed with users age if it is between 25-40.

{% else %}

//Trending products will be displayed to other users.

{% endif %}

Show users special blocks in their local languages

{% if language == Spanish %}

//This Spanish block will be displayed.

{% else %}

//This block will be displayed in the original language.

{% endif %}

Give coupons or discounts according to the customer’s subscription package

{% if c_subscription_package == Gold %}

Hello {{c_subscription_package}} user, check the special offers for you!

//Block with gold users offer will be displayed.

{% elif c_subscription_package == Silver %}

Hello {{c_subscription_package}} user, check the special offers for you!

//Block with silver users offer will be displayed.

{% else %}

Hello there, you can benefit from the offers below!

//General benefits will be displayed.

{% endif %}

Show customers holiday deals according to their travel duration

{% if c_travel_duration >= 1 and c_travel_duration < 5 %}

We are glad to host you for {{c_travel_duration}} days here, these are some advantages you can benefit from:

//Short stay offers will be displayed to users staying between 1-5 days.

{% elif c_travel_duration >= 5 and c_travel_duration < 15 %}

We are glad to host you for {{c_travel_duration}} days here, these are some advantages you can benefit from:

//Long stay offers will be displayed to users staying between 5-15 days.

{% else %}

We are glad to host you here, these are some advantages you can benefit from:

//General advantages will be displayed to other users.

{% endif %}

Promote events like concerts and workshops to your customers who live in that city

{% if city == New York %}

Here are the top events in {{city}}:

//Top events in New York will be displayed.

{% else %}

Here are the top events you can join:

//Top events overall will be displayed.

{% endif %}

Rewarding users for their purchases

{%if (c_spent > 0 and < 100) and (c_reward balance == 0 or c_reward balance == null) %}

// This block will be displayed to users who spent between 0-100 dollars and haven't received any reward yet.

{% else %}

//Email without the reward code will be displayed to users
{% endif %}

Your title goes here
While you can add a combination of conditions for the same email design block, you can also use the and and or operators instead. For example, you can simplify the above use case as {% if (numb > 0 and numb < 100) and (string == 0 or string == empty) %}.
Your title goes here
As you can see in the advanced use cases if you are creating a condition structure with several conditions:
  • Use the if condition for your first condition,
  • Use elif conditions for the upcoming condition,
  • Use else condition as a fallback to cover all cases that might not fit your conditions,
  • ONLY for else condition, add {% endif %} for code after module section.