Yoolk Liquid

Home Basics Operators

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.name == "Awesome Shoes" %}
  These shoes are awesome!
{% endif %}

Operators can be chained together.

{% if product.name == "Shirt" or product.name == "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.name contains 'Pack' %}
  This product's name contains the word Pack.
{% endif %}

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

<!-- assume product.tags returns an array of tags. -->
{% 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_category.products contains 'Awesome Shoes' %}
  One of the products in this category is Awesome Shoes.
{% endif %}

This will work:

{% assign in_product_category = false %}

{% for product in product_category.products %}
  {% if in_product_category == false and product.name == 'Awesome Shoes' %}
    {% assign in_product_category = true %}
  {% endif %}
{% endfor %}

{% if in_product_category %}
  One of the products in this category is Awesome Shoes.
{% endif %}