Welcome to our Help Center

Operators

Liquid has access to all of the logical and comparison operators. These can be used in tags such as if and unless.

Basic Operators

==
  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

Examples:

{% if product.title == "Awesome Shoes" %}
 These shoes are awesome!
{% endif %}

Operators can be chained together.

{% if product.type == "Shirt" or product.type == "Shoes" %}
 This is a shirt or a shoe. 
{% endif %}

The 'contains' Operator

contains checks for the presence of a substring inside a string.

{% if product.title contains 'Pack' %}
 This product's title contains the word Pack.
{% endif %}

contains can also check for the presence of a string in an array of strings.

{% if product.tags contains 'Hello' %}
 This product has been tagged with 'Hello'.
{% endif %}

You cannot check for the presence of an object in an array of objects using contains. This will not work:

{% if product.collections contains 'Sale' %}
 One of the collections this product belongs to is the Sale collection.
{% endif %}

This will work:

{% assign in_sale_collection = false %}
{% for collection in product.collections %}
 {% if in_sale_collection == false and collection.title == 'Sale' %}
 {% assign in_sale_collection = true %}
 {% endif %}
{% endfor %}
{% if in_sale_collection %}
 One of the collections this product belongs to is the Sale collection.
{% endif %}

 

Was this article helpful?

Yes No

Thank you for your feedback!

×
Select company

You are related to multiple companies. Please select the company you wish to login as.