Use list filters to create, manipulate, and display lists.
Removes all null, empty, and invalid (is_valid == false, empty lists, etc..) objects from the list.
list other
Adds all of the items from the other list onto the end of the current list. If either the current object or other is null, they will be treated as an empty list, and if either of them is not a list, they will be treated as a list with a single object.
Example: make a list of two strings
Returns the first item in the current list.
Example: get the first item from a list
string property
Groups the list by the given property and returns the results as a list of objects. Each object in the result set has a Key property which is the value that they are grouped by and a Value property which is the list of objects that have the matching Key property. Any objects in the list that do not have the given property will be in a result with a null Key.
Example: group blog posts by blog
object find number start = -1
Returns the 0-based index of the find object in the current list, or -1 if it cannot be found. If start is greater than 0, the search will begin at the specified index.
Example: find something in a list
string glue = " "
Returns a string with each element from the list joined together with the glue string between elements.
Example: join strings together
Returns the last item in the current list
Example: get the last item in a list
object find number start = -1 boolean ignorecase = false
Returns the last 0-based index of the find object in the current list, or -1 if it cannot be found. If start is greater than 0, the search will begin at the specified index. If the object is a string and ignorecase is true then capitalization will be ignored (note the same does not apply for lists of strings).
Example: find the last occurence of an item in a list
string property
Return a new list with the given property from every object in the original list.
Example: output blog post titles
Reverses the order of the list. This may also be used to reverse a string
Example: reverse the order of blog posts
Return the size of the current list
Example: get the size of a generic list
integer start integer len = 0
Return a portion of the current list. If start is negative, will return len items from the end of the list. If len is 0, will return all remaining characters after start. If len is negative, will return up to len items from the end of the list. This filter may also be used on strings to return a portion of the current string.
Example: Get a portion of a string
string property = null
Sort objects in a list. If theproperty is specified, use it to sort objects in the list by. Use the special string value "random" to sort the list in a random order - which is functionally identicial to using the shuffle filter.
Example: Sort strings
Example: Sort list by custom property
boolean preventCache = true
Sorts the list randomly. Unless preventCache is false, the shuffle filter will prevent the page from being fast-cached.
Example: reorder articles randomly
string property = null
Remove all duplicate objects in the list. If property is specified, objects are considered duplicate if their property value is the same.
Example: Unique array of strings
Example: Limit blog posts to 1 per blog
string property string value
Returns a new list which only contains items where the given property has the given string value
Example: Get list of items with 'position': 'top'
string name string expression
Returns a new list which only contains items that match the given expression when the item is referenced as name.
Example: Reduce list of houses to houses with 2 or more rooms
1) Get two lists: {% datastore_items var featured_houses = datastore:"houses" query:"is_featured = true" %} {% datastore_items var houses_by_folder = datastore:"houses" folder:entity.folder %} 2) Concatenate and uniq the easy way: {% datastore_items var houses = featured_houses houses_by_folder unique %} 3) Concatenate manually: {% var houses = featured_houses | concat: houses_by_folder %} 4) Unique manually: {% var houses = houses | uniq %} 6) Get one random item from the list: {% var random_house = houses | rand %} 7) Sort the full list randomly: {% set houses = houses | shuffle %} 8) Various ways to query and slice: {% var one_rooms = houses | where: "rooms", "1" | sort: "price" %} {% var cheapest = one_rooms | first %} {% var mid_houses = one_rooms | slice: 1, 6 %} {% var expensive_houses = one_rooms | slice: 7 %} {% var num_expensive_houses = expensive_houses | size %} 9) Advanced query: {% var few_rooms = houses | where_exp: "house", "house.rooms.value < 3" %} 10) Grouping: {% var grouped_by_rooms = houses | group_by: "rooms" | sort: "Key" %} {% for list in grouped_by_rooms %} <p>{{list.Key | default: "Unknown"}} Rooms ({{list.Value | size }} houses)</p> {% endfor %} 11) Mapping and Compact: {% var mapped_by_rooms = grouped_by_rooms | map: "Value" %} {% for list in mapped_by_rooms %} <h4>{{list[0].rooms | default: "Unknown"}} Rooms</h4> <ul> <li>{{list | map: "description" | compact | join: "</li><li>" }}</li> </ul> {% endfor %}