Liquid Operators
Liquid has access to all logical and comparison operators. You can use them in tags like if and unless.
Liquid supports basic logical and comparison operators for use with conditional tags.
Operator | Function |
---|---|
== | equals |
!= | does not equal |
> | greater than |
< | less than |
>= | greater than or equal to |
<= | less than or equal to |
or | Condition A or Condition B |
and | Condition A and Condition B |
contains | Checks for strings in strings or arrays |
contains
You can use the contains method to see if a string is in an array or within another string. However, you cannot use contains to check if an object is in an array of objects.
{%-
if product.title contains 'Pack'
-%}
{{ This product’s title contains the word Pack. }}
{%- endif -%}
{{ This product’s title contains the word Pack. }}
{%- endif -%}
Order of operations
When you use multiple operators in a tag, they are processed from right to left, and this order cannot be changed.
Note: Parentheses () are not allowed in Liquid tags. If you use them to group operators, the tag won't work.
{%-
unless true and false and false or true
-%}
{{ This evaluates to false, since Liquid checks tags like this:
true and (false and (false or true))
true and (false and true)
true and false
false }}
{%- endunless -%}
{{ This evaluates to false, since Liquid checks tags like this:
true and (false and (false or true))
true and (false and true)
true and false
false }}
{%- endunless -%}