Skip to main content

first

Returns the first item of an array.
You can use first with dot notation when you need to use the filter inside a tag:

last

Returns the last item of an array.
You can use last with dot notation when you need to use the filter inside a tag:

join

Combines the items in an array into a single string using the argument as a separator.

reverse

Reverses the order of the items in an array. reverse cannot reverse a string.
Although reverse cannot be used directly on a string, you can split a string into an array, reverse the array, and rejoin it by chaining together filters:

size

Returns the number of characters in a string or the number of items in an array.
You can use size with dot notation when you need to use the filter inside a tag:

sort

Sorts items in an array in case-sensitive order.
An optional argument specifies which property of the array’s items to use for sorting.

sort_natural

Sorts items in an array in case-insensitive order.
An optional argument specifies which property of the array’s items to use for sorting.

map

Creates an array of values by extracting the values of a named property from another object. In this example, assume the object site.pages contains all the metadata for a website. Using assign with the map filter creates a variable that contains only the values of the category properties of everything in the site.pages object.

concat

Concatenates (joins together) multiple arrays. The resulting array contains all the items from the input arrays.
You can string together concat filters to join more than two arrays:

uniq

Removes any duplicate elements in an array.

where

Creates an array including only the objects with a given property value, or any truthy value by default. In this example, assume you have a list of products and you want to show your kitchen products separately. Using where, you can create an array containing only the products that have a "type" of "kitchen".
Say instead you have a list of products and you only want to show those that are available to buy. You can where with a property name but no target value to include all products with a truthy "available" value. As a special case, the same will happen if the target value is given but evaluates to undefined.
The where filter can also be used to find a single object in an array when combined with the first filter. For example, say you want to show off the shirt in your new fall collection.
Additionally, property can be any valid Liquid variable expression as used in output syntax, except that the scope of this expression is within each item. For the following products array:

slice

Returns a substring of 1 character beginning at the index specified by the first argument. An optional second argument specifies the length of the substring to be returned. String indices are numbered starting from 0.
If the first argument is a negative number, the indices are counted from the end of the string:

where_exp

Select all the objects in an array where the expression is true. In this example, assume you have a list of products and you want to show your kitchen products separately. Using where_exp, you can create an array containing only the products that have a "type" of "kitchen".

find

Return the first object in an array for which the queried attribute has the given value or return nil if no item in the array satisfies the given criteria. For the following members array:

find_exp

Return the first object in an array for which the given expression evaluates to true or return nil if no item in the array satisfies the evaluated expression.

find_index

Return the 0-based index of the first object in an array for which the queried attribute has the given value or return nil if no item in the array satisfies the given criteria. For the following members array:

find_index_exp

Return the 0-based index of the first object in an array for which the given expression evaluates to true or return nil if no item in the array satisfies the evaluated expression.

group_by

Group an array’s items by a given property. For members array:

group_by_exp

Group an array’s items using a Liquid expression. For members array below:

has

Return true if the array includes an item for which the queried attribute has the given value or return false if no item in the array satisfies the given criteria. For the following members array:

has_exp

Return true if an item exists in an array for which the given expression evaluates to true or return false if no item in the array satisfies the evaluated expression.

compact

Removes any nil values from an array. For this example, assume site.pages is an array of content pages for a website, and some of these pages have an attribute called category that specifies their content category. If we map those categories to an array, some of the array items might be nil if any pages do not have a category attribute.
By using compact when we create our site_categories array, we can remove all the nil values in the array.

push

Push an element into array. It’s NON-DESTRUCTIVE, i.e. it does not mutate the array, but rather make a copy and mutate that.

pop

Pop an element from the array. It’s NON-DESTRUCTIVE, i.e. it does not mutate the array, but rather make a copy and mutate that.

shift

Shift an element from the array. It’s NON-DESTRUCTIVE, i.e. it does not mutate the array, but rather make a copy and mutate that.

unshift

Unshift an element to the front of the array. It’s NON-DESTRUCTIVE, i.e. it does not mutate the array, but rather make a copy and mutate that.

reject

Creates an array excluding the objects with a given property value, or excluding truthy values by default when a property is not given. In this example, assume you have a list of products and you want to filter out kitchen products. Using reject, you can create an array excluding only the products that have a "type" of "kitchen".
Say instead you have a list of products and you want to exclude taxable products. You can reject with a property name but no target value to reject all products with a truthy "taxable" value.
Additionally, property can be any valid Liquid variable expression as used in output syntax, except that the scope of this expression is within each item. For the following products array:

reject_exp

Select all the objects in an array where the expression is false. In this example, assume you have a list of products and you want to hide your kitchen products. Using reject_exp, you can create an array that omits only the products that have a "type" of "kitchen".