These filter work on an array/list objects. They are helpful on collection lists, product lists or completely different kinds of lists. The following filter are available in this section:
This filter creates a new list from a list of objects, where all attributes of a given name will be extracted to form the new list. This filter is similar to the map filter, but collapse should be used if the attribute is itself a list and the result should be a single list including all items of the several lists.
Example:
{{ collection.products | size }}
{{ collection.products | collapse: 'variants' | size }}
Output:
2
6
The term collection.products is a list of type Product. Product objects have a field called variants, which are lists of supported variants. Therefore {{ collection.products | collapse: ‘variants’ }} is a list of the union of the variant fields of each Product (thus the result is a list of Variant, as Variants is a List<Variant> – but of course it will also work with lists of numerical values or list of strings).
Note: This filter is exclusive to FlickRocket.
Filters an array/list regarding a specific attribute, only elements with that attribute having a specific value will be in the resulting list.
Example:
{{ collection.products | filter: 'rating', 40 }}
Output:
Tears of Steel
Elephants Dream
Note: This filter is exclusive to FlickRocket.
Gets the first element of an array/list
Example:
{% assign cp = collection.products | first %}
{{ cp.title }}
Output:
Big Buck Bunny
Intersects two arrays, the result are the elements which occur in both lists.
Example:
{% assign list_a = 'red green blue' | split: ' ' %}
{% assign list_b = 'yellow red blue black' | split: ' ' %}
{{ list_a | intersect: list_b | join ', ' }}
Output:
red blue
Note: This filter is exclusive to FlickRocket.
This filter lets you join elements of the array with a certain string between them. The so-called glue string can be passed as a parameter, if it is missing it will be a whitespace.
Example:
{{ product.actors | join }}
{{ product.actors | join: ' & ' }}
Output:
Jody Bhe Chris Haley Sergio Hasselbaink Derek de Lint Denise Rebergen Vanja Rukavina Rogier Schippers
Jody Bhe & Chris Haley & Sergio Hasselbaink & Derek de Lint & Denise Rebergen & Vanja Rukavina & Rogier Schippers
last
Returns the last element of the given array.
Example:
{{ product.actors | last }}
Output:
Rogier Schippers
This filter creates a new list from a list of objects, where all attributes of a given name will be extracted to form the new list. This filter is quite similar to the collapse filter, but in this case the attribute need to be an object not a list/array.
Example:
{{ collection.products | map: 'title' | join: '<br/>' }}
Output:
Big Buck Bunny<br/>Elephants Dream
The term collection.products is a list of type Product. Product objects have a field called title. Therefore {{ collection.products | map: ‘title’ }} is a list of the title fields of each Product (thus the result is a list of strings, as title is a string – but of course it will also work with lists of numerical values or list of objects).
This filter merges two arrays/lists to one. If an element occurs in both lists, it will only be stored once in the result array.
Example:
{{ collections['animation'].products | map: 'title' | join: ', ' }}
{{ collections['comedy'].products | map: 'title' | join: ', ' }}
{{ collections['animation'].products | merge: collections['comedy'].products | map: 'title' | join: ', ' }}
Output:
Big Buck Bunny, Elephants Dream
Star Wreck: In the Pirkinning, Big Buck Bunny
Big Buck Bunny, Elephants Dream, Star Wreck: In the Pirkinning
Note: This filter is exclusive to FlickRocket.
This filter removes a specific element from the array. The array can contain objects of any type.
Example:
{% assign pl = collection.products | remove: collection.products[0] %}
{{ collection.products.size }}
{{ pl.size }}
Output:
2
1
Note: This filter is exclusive to FlickRocket.
Reverses the content of the array. Afterwards, the last element will be the first and the first will be the last, etc. This command does not a sort, it will just change the order of the elements top-down!
Example:
{{ product.actors | join: ', ' }}
{{ product.actors | reverse | join: ', ' }}
Output:
Stefan Kluge, Gerald Menze, Mathias Eimann
Mathias Eimann, Gerald Menze, Stefan Kluge
This filter returns the number of elements contained in the array/list.
Example:
{{ collection.products | size }}
Output:
2
Sorts the elements of the array. If it is an array of strings or numeric values, the strings will be sorted lexigraphically or numerically in an ascending order. If it is a list of objects, you need to additionally specify a parameter which denotes what field of the object will be used for sorting. In order to sort in descending order, just use the reverse filter after you have sorted.
Example:
{{ product.actors | sort | join: ', ' }}
{{ product.subtitles | sort: 'description' | reverse | map: 'description' | join: ', '}}
Output:
Antti Satama, Atte Joutsen, Janos Honkonen, Jari Ahola, Karoliina Blackburn, Samuli Torssonen, Seppo Honkanen, Sonja Sjöblom, Tiina Routamaa, Timo Vuorensola
Swedish, Spanish, Italian, German, French, Finnish, English
The product.subtitles field contains a list of SubtitleInformation objects. These objects contain an attribute called description (usually the name of the subpicture). The list of objects is sorted regarding this field, the output is still a list of SubtitleInformation. Afterwards the list is reversed (so that it is still a list of SubtitleInformation). Then finally, that field is mapped using the map filter, therefore the result is a list of strings. Finally all strings are concatenated using the join filter (using a glue-string of ‘, ‘). Of course it would have been possible to first map the description field and then sort without using a parameter (as it would sort a list of strings in that case), but the example should show how to use the additional parameter for the sort filter.
Take a string and split it by the given char into an array
{% assign list_a = 'red green blue' | split: ' ' %}
This filter removes duplicates from an array.
Example:
{{ 'red blue green red purple' | split: ' ' | uniq | join: ' ' }}
Output:
red blue green purple