Array filters for working with collections in Liquid templates.
first
first
with dot notation when you need to use the filter inside a tag:
last
last
with dot notation when you need to use the filter inside a tag:
join
reverse
reverse
cannot reverse a string.
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
size
with dot notation when you need to use the filter inside a tag:
sort
sort_natural
map
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
concat
filters to join more than two arrays:
uniq
where
where
, you can create an array containing only the products that have a "type"
of "kitchen"
.
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
.
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.
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
where_exp
where_exp
, you can create an array containing only the products that have a "type"
of "kitchen"
.
find
nil
if no item in the array satisfies the given criteria. For the following members
array:
find_exp
nil
if no item in the array satisfies the evaluated expression.
find_index
nil
if no item in the array satisfies the given criteria. For the following members
array:
find_index_exp
nil
if no item in the array satisfies the evaluated expression.
group_by
members
array:
group_by_exp
members
array below:
has
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
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
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.
compact
when we create our site_categories
array, we can remove all the nil
values in the array.
push
pop
shift
unshift
reject
reject
, you can create an array excluding only the products that have a "type"
of "kitchen"
.
reject
with a property name but no target value to reject all products with a truthy "taxable"
value.
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
reject_exp
, you can create an array that omits only the products that have a "type"
of "kitchen"
.