Arrays

Working With Arrays

These filters help you in working with arrays.

 

Contains

Show Details
Server: v8.0

The contains filter returns true if the specified value is in the array

 

First

Show Details
Server: v1.0

Returns the first item from an array/collection.

 

Index

Show Details
Server: v7.0

Provides an easy way to retrieve an item from an array using its index when chaining filters.

 

Indexer

Show Details
Server: v7.0

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

 

Join

Show Details
Server: v1.0

Combines the properties of an array with the character passed as the parameter.

 

Last

Show Details
Server: v1.0

Returns the last item from an array/collection.

 

Map

Show Details
Server: v1.0

Takes a property of the array as a parameter and creates a string out of each array property value.

 

OrderBy

Show Details
Server: v10.0

Orders a collection of elements by the specified property tree and returns a new collection in that order.

 

Select

Show Details
Server: v4.0

Returns a single property from an object.

 

Shuffle

Show Details
Server: v4.0

Randomizes the order of an array. Useful for ads on a homepage where you'd like a different ad to be first for each visit.

 

Size

Show Details
Server: v1.0

Provides the number of items in the array.

 

Sort

Show Details
Server: v1.0

Sorts the array/collection based on the property provided (note: does not work with attribute values).

 

SortByAttribute

Show Details
Server: v5.0

Sorts an array of items based on a attribute value.

 

Uniq

Show Details
Server: v8.0

Takes a collection of values and returns only the unique set of those values.

 

Where

Show Details
Server: v4.0

This filter allows you to filter a collection of items by a key and value.

Array Filters In Action

Reading through the filters above you might question the value of many of them. For instance what good is the 'Map' filter when it just returns a string of array values all smashed together (Avalon CampusTacoma CampusCorolla Campus). The power comes when you chain these filters together. Consider the kitchen sink example below.

{% assign sortedCampuses = Campuses | Sort:'Name' %}
{{ sortedCampuses | Map:'Name' | Join:', ' | ReplaceLast:',',' and' }}

Output:
Avalon Campus, Corolla Campus and Tacoma Campus