Conditional statements control when content is shown in a template. They allow messages to adapt dynamically based on customer attributes, event data, or system values, without requiring multiple versions of the same template.
In Liquid, conditional statements are written as structured blocks. Each condition is evaluated at send time, and only the content that meets the condition is rendered in the final message.
Single-Level Conditions
Single-level conditions are used to evaluate rules and determine which
content is shown. These include if, else,
elsif, and, and or.
IF
IF statements control whether content is shown based on one condition. The condition is evaluated at send time. If it is true, the content inside the block is rendered. If false, the content is skipped.
Use if for optional personalization.
{% if user.SUPPORTER == "Tottenham" %}
COYS! Matchday coverage just for Spurs fans
{% endif %}
- If SUPPORTER = "Tottenham": COYS! Matchday coverage just for Spurs fans
- If SUPPORTER is anything else: Content is skipped entirely
OR
OR conditions control whether content is shown when any one of multiple conditions can be true. If at least one condition is true, the content is rendered. If all conditions are false, the content is skipped.
Use or to broaden eligibility for the same outcome.
{% if user.SUPPORTER == "Tottenham" or user.SUPPORTER == "Liverpool" %}
You qualify for a special supporter offer!
{% endif %}
- If SUPPORTER = "Tottenham" or "Liverpool": You qualify for a special supporter offer!
- If SUPPORTER is anything else: Content is skipped
AND
AND conditions control whether content is shown when all conditions must be true. If any condition is false, the content is skipped.
Use and to narrow eligibility.
{% if customer.SUPPORTER == "Tottenham" and customer.VIPSTAGE == "Platinum" %}
Exclusive Platinum Spurs offer unlocked!
{% endif %}
- If SUPPORTER = "Tottenham" and VIPSTAGE = "Platinum": Exclusive Platinum Spurs offer unlocked!
- If either condition is false: Content is skipped
ELSIF
ELSIF is used when different conditions lead to different outcomes. Conditions are evaluated in order at send time. The first condition that evaluates as true renders its content, and all remaining conditions are skipped.
{% if customer.VIPSTAGE == "Platinum" %}
Platinum members get priority access to exclusive matchday experiences.
{% elsif customer.VIPSTAGE == "Gold" %}
Gold members unlock special matchday rewards.
{% endif %}
- If VIPSTAGE = "Platinum": Platinum message is shown
- If VIPSTAGE = "Gold": Gold message is shown
- If VIPSTAGE is anything else: No content is shown
IF / ELSE Fallbacks
Fallbacks protect your template when data is missing or when none of
your primary conditions are met. If the first conditions are not met,
else provides a controlled alternative.
Use if / else when the structure of the content
needs to change. Use filters (like default) when only a
single value needs replacing.
{% if customer.VIPSTAGE == "Platinum" %}
Platinum members get priority access to exclusive matchday experiences.
{% elsif customer.VIPSTAGE == "Gold" %}
Gold members unlock special matchday rewards.
{% else %}
Not a VIP yet? Register to join our exclusive club!
{% endif %}
- If VIPSTAGE = "Platinum": Platinum message
- If VIPSTAGE = "Gold": Gold message
- If VIPSTAGE = anything else: Generic registration prompt
else block when there
is a possibility that none of your conditions will be met.
Nested Conditions
Nested logic is used when conditions must be evaluated in sequence rather than at the same level. It allows you to control evaluation order, group related logic, create hierarchical decisions, and prevent unnecessary evaluations.
Nesting structures decisions, not just additional conditions.
Sequential Nesting
Nested conditions evaluate one rule before checking another. The second condition (B) is only checked if the first condition (A) is true. Use this when a second rule only matters if the first passes.
{% if A %}
{% if B %}
Content shown only when both A and B are true
{% endif %}
{% endif %}
Nested Branching
Nested branching creates a decision tree with grouped logic under one parent rule and controlled alternatives at each level.
{% if A %}
{% if B %}
Content for A + B
{% elsif C %}
Content for A + C
{% endif %}
{% endif %}
Real-World Example: Product Category Personalization
Here is a practical example that personalizes content based on a customer's favourite product category and specific product name.
{% if user.ECOM_FAVORITE_PRODUCT_CATEGORY == "Trousers" %}
{% if user.ECOM_FAVORITE_PRODUCT_NAME == "Rhythm Merino Pants Short" %}
Your favourite trousers are back - the Rhythm Merino Pants Short.
{% else %}
Discover our latest trousers.
{% endif %}
{% else %}
Explore our latest arrivals.
{% endif %}
- Favourite category = "Trousers" and favourite product = "Rhythm Merino Pants Short": Your favourite trousers are back - the Rhythm Merino Pants Short.
- Favourite category = "Trousers" and a different product: Discover our latest trousers.
- Favourite category is something else: Explore our latest arrivals.
Common Mistakes to Avoid
-
Forgetting
endif: Every{% if %}block must have a matching{% endif %}. With nested conditions, make sure you have oneendiffor eachif. -
Using output tags inside logic: Do not use
{{ }}inside a logic tag. Write{% if user.COUNTRY == "UK" %}, not{% if {{ user.COUNTRY }} == "UK" %}. -
Condition order matters with
elsif: The first matching condition wins. Place your most specific conditions first and your most general conditions last.