Liquid has access to all of the logical and comparison operators. These can be used in tags such as if and unless.
==
!=
>
<
>=
<=
or
and
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 %}
contains checks for the presence of a substring inside a string.
contains
{% 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 helpfu?
Thank you for voting
You are related to multiple companies. Please select the company you wish to login as.