Operators define the comparison or logical criteria evaluated within conditional content, such as {% if %} and {% elsif %}.
Comparison operators
Operator | Meaning | Example |
|---|---|---|
== | Equal to | {% if name == "Alice" %} |
!= | Not equal to | {% if c_loyalty_tier != "gold" %} |
> | Greater than | {% if age > 18 %} |
< | Less than | {% if c_total_orders < 5 %} |
>= | Greater than or equal | {% if age >= 18 %} |
<= | Less than or equal | {% if c_total_orders <= 5 %} |
contains | String or array contains value | {% if email contains "@" %} |
Comparisons are type-sensitive. You can compare numbers to numbers and strings to strings. For example, "5" > 3 is not valid. You need to use numbers on both sides.
Logical operators
Operator | Meaning | Example |
|---|---|---|
and | Both must be true | {% if name != blank and age > 18 %} |
or | At least one must be true | {% if c_loyalty_tier == "gold" or c_total_orders >= 10 %} |
Grouping conditions without parentheses
Parentheses are not supported in Liquid conditions. You need to use nested if blocks instead.
Liquid evaluates conditions strictly left-to-right. When in doubt, you need to use nested {% if %} blocks for clarity.
{# Wrong — parentheses are not supported #}
{% if (c_loyalty_tier == "gold" or c_loyalty_tier == "silver") and age > 18 %}
{# Correct — use nested blocks #}
{% if age > 18 %}
{% if c_loyalty_tier == "gold" or c_loyalty_tier == "silver" %}
Content for adult loyalty members.
{% endif %}
{% endif %}contains
This operator checks whether a string contains a substring, or whether an array contains a value.
{% if email contains "@" %}
Looks like a valid email.
{% endif %}
{% if tags contains "premium" %}
Premium content shown here.
{% endif %}For arrays of simple values (strings/numbers), contains works as above. For arrays of objects, it only matches if the element equals the value exactly, not by a field inside the object.