-
EQUAL (==)
The EQUAL operator
Input==
is used to evaluate whether something is true.{% assign color = "blue" -%} {% if color == 'Blue' -%} <p>The color is Blue.</p> {% endif -%}
OutputThe color is Blue.
-
DOES NOT EQUAL (!=)
The DOES NOT EQUAL operator
Input!=
is used to evaluate whether something is false (or not equal to the other).{% if red != 'Blue' -%} <p>The color is not Blue.</p> {% endif -%}
OutputThe color is not Blue.
-
GREATER THAN (>)
The GREATER THAN
Input>
is used to evaluate whether something is greater than the compared value.{% if 10 > 4 -%} <p>10 is greater than 4</p> {% endif -%}
Output10 is greater than 4
-
LESS THAN (<)
The LESS THAN
Input<
is used to evaluate whether something is less than the compared value.{% if 4 < 10 -%} <p>4 is less than 10</p> {% endif -%}
Output4 is less than 10
-
GREATER THAN OR EQUAL TO (>=)
The GREATER THAN OR EQUAL TO
Input>=
is used to evaluate whether something is greater than or equal to the compared value.{% if 10 >= 10 -%} <p>10 is greater than or equal to 10</p> {% endif -%}
Output10 is greater than or equal to 10
-
LESS THAN OR EQUAL TO (<=)
The LESS THAN OR EQUAL TO
Input<=
is used to evaluate whether something is less than or equal to the compared value.{% if 4 <= 10 -%} <p>4 is less than or equal to 10</p> {% endif -%}
Output4 is less than or equal to 10
Misc Operators
In tags with more than one AND
or OR
operator, the operators are checked from right to left. You cannot change the order of operations using parentheses as parentheses are invalid characters in Liquid and will prevent your tags from rendering.
-
OR
The OR decision operator renders true if one or both of the evaluated values is true.
Input{% if blue == 'blue' or 'red' -%} <p>The color is Blue or Red.</p> {% else -%} <p>The color is Green.</p> {% endif -%}
OutputThe color is Blue or Red.
-
AND
Decision operators that renders true if both of the evaluated values is true.
Input{% if {{itemColor}} == 'Blue' and {{itemSize}} == 'large' -%} <p>The shirt is Blue and size Large.</p> {% else -%} <p>The shirt is out of stock.</p> {% endif -%}
OutputThe shirt is Blue and size Large.
-
CONTAINS
You can use
CONTAINS
to check whether a string contains another string.
InputCONTAINS
can only search string values. You cannot use it to check for an object in an array of objects.{% if {{itemColor}} contains 'Blue' -%} <p>The color is Blue.</p> {% else -%} <p>Blue shirts are out of stock.</p> {% endif -%}
OutputThe color is Blue.