LiquidJS operators are very simple and different. There are 2 types of operators supported:
- Comparison operators:
==,!=,>,<,>=,<= - Logical operators:
not,or,and,contains
Thus arithmetic operators are not supported and you cannot add two numbers like this {{a + b}}. Instead, use a filter: {{ a | plus: b}}. Actually + is a valid variable name in LiquidJS.
Logical Operators
not
Negates a condition. Returns true if the condition is false, and false if the condition is true.
Input
{% if not user.active %}
User is inactive
{% endif %}
and
Returns true if both conditions are true.
Input
{% if user.age >= 18 and user.verified %}
Access granted
{% endif %}
or
Returns true if at least one condition is true.
Input
{% if user.isAdmin or user.isModerator %}
You have elevated privileges
{% endif %}
contains
Checks if a string contains a substring, or if an array contains an element.
Input
{% if product.title contains "Pack" %}
This is a pack
{% endif %}
Precedence
- Comparison operators, and
contains. All comparison operators alongsidecontainshave the same (highest) precedence. notoperator. It has slightly more precedence thanorandand.orandandoperators. These logical operators have the same (lowest) precedence.
Associativity
Logical operators are evaluated from right to left, see shopify docs.