Build Your Course The Easy Way
Get Started Free

Array Filters

Filters to be used on any object or method that returns an array / collection.

In this article:


join

Joins the elements of an array or collection with the character passed as the parameter. The result is a single string.

<p>Tags: {{ blog_post.tags | join: ', ' }}</p>

first

Returns the first element of an array.

<p>First Tag: {{ blog_post.tags | first }}</p> first can also be called via the dot (.) notation. Using this method, you can call addition methods afterwards.

<p>First Lesson: {{ product.categories.first.posts.first.title }}</p>

last

Returns the last element passed in an array.

<p>Last Tag: {{ blog_post.tags | last }}</p> last can also be called via the dot (.) notation. Using this method, you can call addition methods afterwards.

<p>Last Lesson: {{ product.categories.last.posts.last.title }}</p>

index

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].

<p>Second Tag: {{ blog_post.tags[1] }}</p>

size

Returns the size of a string or an array.

<p>There are {{ product.categories | size }} lessons in this course.</p> size can also be called via the dot (.) notation.

<p>{{ product.title }} has {{ product.title.size }} characters in it!</p>

sort

Sorts the elements of an array by a given attribute of an element in the array.

{% assign tags_by_size = blog_post.tags | sort: 'size' %} <p>Tags by size: {{ tags_by_size | join: ", " }}</p>

Contact support or access our 24/7 Live Chat:

Contact Support Live Chat

Need Help? Live Chat with Us.