Arrays

Working With Arrays

These filters help you in working with arrays.

 

AddToArray

Show Details
Server: v13.0

Add a new item to an existing array.

 

AddToDictionary

Show Details
Server: v13.0

Takes an existing (or empty) dictionary and returns a new dictionary with the added key and value.

 

AllKeysFromDictionary

Show Details
Server: v13.0

Retrieves all keys that exist in the dictionary object and returns them in an array.

 

Compact

Show Details
Server: v16.0

Removes empty or null values from an array.

 

Concat

Show Details
Server: v16.0

Joins multiple arrays together so that the result contains all the items from the input arrays.

 

Contains

Show Details
Server: v8.0 Mobile: v1.0

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

 

Distinct

Show Details
Server: v13.0

Takes an array as input and returns the distinct (unique) elements of the array.

 

First

Show Details
Server: v1.0 Mobile: v1.0

Returns the first item from an array/collection.

 

GroupBy

Show Details
Server: v13.0

Takes a collection of items and groups them by the specified property tree value.

 

Index

Show Details
Server: v7.0 Mobile: v1.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 Mobile: v1.0

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

 

Last

Show Details
Server: v1.0 Mobile: v1.0

Returns the last item from an array/collection.

 

Map

Show Details
Server: v1.0 Mobile: 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 Mobile: v1.0

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

 

RemoveFromArray

Show Details
Server: v13.0

Take a collection of objects and return a new collection which does not contain the specified value.

 

RemoveFromDictionary

Show Details
Server: v13.0

Removes the specified key from a dictionary of keys and values.

 

Reverse

Show Details
Server: v14.0

Reverses the order of the items in an array.

 

Select

Show Details
Server: v4.0 Mobile: v1.0

Returns a single property from an object.

 

Shuffle

Show Details
Server: v4.0 Mobile: v1.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 Mobile: v1.0

Provides the number of items in the array.

 

Slice (arrays)

Show Details
Server: v13.1

The slice filter (when used on an array) returns a subset of the given array, starting at the specified index. An optional second parameter can be passed to specify the length of the subset. If no second parameter is given, a subset of one item will be returned.

 

Sort

Show Details
Server: v1.0 Mobile: v1.0

Sorts a primitive array (in case-sensitive order in Fluid). To sort by the properties of an array, use OrderBy.

 

SortByAttribute

Show Details
Server: v5.0

Sorts an array of items based on an attribute value.

 

SortNatural

Show Details
Server: v16.0

Fluid only: Sorts a primitive array, in case-insensitive order. To sort by the properties of an array, use OrderBy.

 

Sum

Show Details
Server: v13.0

Performs a mathematical summation of all numeric values in an array and outputs the result.

 

Uniq

Show Details
Server: v8.0 Mobile: v1.0

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

 

Where

Show Details
Server: v4.0 Mobile: v1.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