Comparisons

Liquid provides many advanced ways to compare your objects and variables when using conditionals. Comparing items is a mixture of conditions, contexts, and logic gates. Knowing all your options can give you lots of different ways to test and vary your templates.

Logic Gates

Liquid understands both and and or logic gates for testing multiple conditions in the same statement.

{% if item.data.age >= 15 and item.data.age < 25 %}
  You can drive, but not rent a car.
{% endif %}

{% if item.slug == 'html' or item.slug == 'css' %}
  Basic front-end development.
{% endif %}

Comparisons

Liquid provides the following comparisons to use in your conditional statements.

Comparison Description
== Is equal to
!= Is not equal to
<> Is not equal to
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
contains The left collection includes the right value

Contexts

Any of the following can be used on either side of a comparison.

Context Description
nil or null Does not exist
true Is true
false Is false
blank Either does not exist, or is an empty string
empty Does not contain any items (for collections)
variable Any variable in the current context
‘string’ or “string” A quoted string
(x..y) A range from x to y eg. (0..20)
x Any integer or float