Shopify/Liquid Filter Syntax

How to use filters on objects and on logic statements

Written By Guilherme de Andrade Arantes (Administrator)

Updated at May 20th, 2020

Every time you need to limit a loop statement or change the output of an object value, you can rely on Liquid Filters.

Limit filter

The following example is the same example found in the Shopify/Liquid Logic Syntax page‍ plus the limit filter:

<ul class="top_categories">
{% for categories in roots_categories | limit: 5 %}
  <li class="category_item">
    <a href="{{ category.url }}" class="category_link">{{ }}</a>
{% endif %}

Notice that we added the limit filter on the For Statement syntax:

{% for categories in roots_categories | limit: 5 %}

Now, the category list has 5 maximum items. It can be smaller but it cannot display more than 5 items.

Size filter

The size filter will output the size of the object value if it's a string or the length of a list:

{% | size %}

The above example would output the size of the question name.

{% if category.questions.size > 10 %}
  <p>There are more than 10 questions in this category!</p>
{% else %}
  <p>There are 10 or less questions in this category.</p>
{% endif %}

Notice that the size filter can be use as an object attribute on a logical statement:

{% if category.questions.size > 10 %}{% endif %}

Downcase filter

The downcase filter will convert the string to downcase:

{{ "Getting Started" | downcase }}

The above example would output:

getting started

All Liquid Filters

The official Shopify/Liquid documentation has a complete filters guide on its docs page.

Objects List

You can find the complete object reference at Shopify/Liquid Complete Objects Reference‍.

Advanced Shopify/Liquid Syntax

You can find more information about Logical Statements on the official Liquid documentation. The complete Shopify/Liquid documentation is located here.

Was this article helpful?