Liquid operators
Liquid operators are used with tags to control flow.
If you've done any computer programming before, you'll be familiar with operators. In Liquid, operators let you make logical decisions and comparisons.
For example, you might need to check if a particular number is bigger than another number, or check to see if something has been filled in.
Main operators
Operator
Function
==
equals
!=
does not equal
>
greater than
<
less than
>=
greater than or equal to
<=
less than or equal to
or
logical or
and
logical and
For example, here we use less than to print a statement if an opportunity charge total is less than 100.
{% if order.charge_excluding_tax_total < 100 %}
Spend some more money with us!
{% endif %}
contains
contains
Use contains
to check for the presence of a substring in a string.
{% if customer.email contains "current-rms.com" %}
You work for Current RMS, lucky you!
{% endif %}
It's especially useful for multi-select custom fields, where selected list options are stored as a comma-separated string.
Order of operations
In tags with more than one and
or or
operator, operators are checked in order from right to left.
{% if true or false and false %}
This evaluates to true, since the 'and' condition is checked first.
{% endif %}
{% if true and false and false or true %}
This evaluates to false, since the tags are checked like this:
true and (false and (false or true))
true and (false and true)
true and false
false
{% endif %}
Last updated
Was this helpful?