Array filters are used to modify the output of arrays.
Joins the elements of an array with the character passed as the parameter. The result is a single string.
Input
{{ product.tags | join: ', ' }}
Output
tag1, tag2, tag3
Returns the first element of an array.
<!-- product.tags = "sale", "mens", "womens", "awesome" --> {{ product.tags | first }}
sale
first can be used in dot notation, in cases where it needs to be used inside a tag.
first
{% if product.tags.first == "sale" %} This product is on sale! {% endif %}
Gets the last element passed in an array.
<!-- product.tags = "sale", "mens", "womens", "awesome" --> {{ product.tags | last }}
awesome
last can be used in dot notation, in cases where it needs to be used inside a tag.
last
{% if product.tags.last == "sale"%} This product is on sale! {% endif %}
Using last on a string returns the last character in the string.
<!-- product.title = "Awesome Shoes" --> {{ product.title | last }}
s
Returns the item at the specified index location in an array. Note that array numbering starts from zero, so the first item in an array is referenced with [0].
[0]
<!-- product.tags = "sale", "mens", "womens", "awesome" --> {{ product.tags[2] }}
womens
Accepts an array element's attribute as a parameter and creates a string out of each array element's value.
<!-- collection.title = "Spring", "Summer", "Fall", "Winter" --> {% assign collection_titles = collections | map: 'title' %} {{ collection_titles }}
SpringSummerFallWinter
Returns the size of a string or an array.
{{ 'is this a 30 character string?' | size }}
30
size can be used in dot notation, in cases where it needs to be used inside a tag.
size
{% if collections.frontpage.products.size > 10 %} There are more than 10 products in this collection! {% endif %}
Sorts the elements of an array by a given attribute of an element in the array.
{% assign products = collection.products | sort: 'price' %} {% for product in products %} <h4>{{ product.title }}</h4> {% endfor %}
The order of the sorted array is case-sensitive.
<!-- products = "a", "b", "A", "B" --> {% assign products = collection.products | sort: 'title' %} {% for product in products %} {{ product.title }} {% endfor %}
A B a b
Was this article helpfu?
Thank you for voting
You are related to multiple companies. Please select the company you wish to login as.