compact filter
Removes all null, empty, and invalid (is_valid == false, empty lists, etc..) objects from the list.
Liquid filters for lists (sort, where, map, etc.).
Removes all null, empty, and invalid (is_valid == false, empty lists, etc..) objects from the list.
Remove null and empty from a list
{%- var mixed = ',,,a,,,b,b,,c,,' | split: ',' -%}
{{- mixed | compact | join: ',' }} <- {{ mixed | join: ',' -}}a,b,b,c <- ,,,a,,,b,b,,c,,
The list is output twice. The first time it uses compact to remove all of the empty strings from the list and the second time is without modification to show that the original list was not modified. Note that the compact filter does not remove duplicates.
After map or other operations
{%- var descriptions = items | map: 'description' | map: 'value' | compact -%}
{%- if descriptions is_valid -%}
<ul>
{%- for d in descriptions -%}
<li>{{ d }}</li>
{%- endfor -%}
</ul>
{%- endif -%}Useful after mapping to a property that may be missing on some items, so you only iterate over present values.
When the list may contain invalid items
{%- var valid_props = entity.data.properties | map: 'Value' | compact -%}
{%- if valid_props is_valid -%}
<dl>
{%- for p in valid_props -%}
<dt>{{ p.field_id }}</dt>
<dd>{{ p.value | escape}}</dd>
{%- endfor -%}
</dl>
{%- endif -%}When the list may contain invalid items, you can use the compact filter to remove them. In this example, entity.data.properties is assumed to contain a list of objects which may contain some invalid objects. The compact filter is then used to remove all of the invalid objects from the list before outputting it to the page.
{%- datastore_items var featured_houses = datastore:"houses" query:"is_featured = true" -%}
{%- datastore_items var houses_by_folder = datastore:"houses" folder:entity.folder -%}Concatenate and uniq the easy way
{% datastore_items var houses = featured_houses houses_by_folder unique %}Concatenate manually
{% var houses = featured_houses | concat: houses_by_folder %}Unique manually
{% var houses = houses | uniq %}Get one random item from the list
{% var random_house = houses | rand %}Get a random item from the list. Prevents the page from being fast-cached, and every time the page is loaded a new random item will be chosen.
Get one random item from the list and allow fast-caching
{% var random_house = houses | rand:1, false, false %}Get a random item from the list and allow the page to be fast-cached, resulting in much faster pageload speeds but the same random item will be used until the fast cache expires.
Sort the full list randomly
{% set houses = houses | shuffle %}Sort the full list randomly. The page will not be able to be fast-cached, and every time the page is loaded a new random order will be chosen. To allow the page to be fast-cached, pass false to the shuffle command.
Various ways to filter 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 -%}Advanced filter
{% var few_rooms = houses | where_exp: "house", "house.rooms.value < 3" %}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 -%}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 -%}Adds all of the items from the other list onto the end of the input list.
If either the input or other is not a list, it will be treated as a list with a single object. If either is null, it will be treated as an empty list.
{% "a" | concat:"b" | json_encode %}["a", "b"]
{%- datastore_items var featured_houses = datastore:"houses" query:"is_featured = true" -%}
{%- datastore_items var houses_by_folder = datastore:"houses" folder:entity.folder -%}Concatenate and uniq the easy way
{% datastore_items var houses = featured_houses houses_by_folder unique %}Concatenate manually
{% var houses = featured_houses | concat: houses_by_folder %}Unique manually
{% var houses = houses | uniq %}Get one random item from the list
{% var random_house = houses | rand %}Get a random item from the list. Prevents the page from being fast-cached, and every time the page is loaded a new random item will be chosen.
Get one random item from the list and allow fast-caching
{% var random_house = houses | rand:1, false, false %}Get a random item from the list and allow the page to be fast-cached, resulting in much faster pageload speeds but the same random item will be used until the fast cache expires.
Sort the full list randomly
{% set houses = houses | shuffle %}Sort the full list randomly. The page will not be able to be fast-cached, and every time the page is loaded a new random order will be chosen. To allow the page to be fast-cached, pass false to the shuffle command.
Various ways to filter 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 -%}Advanced filter
{% var few_rooms = houses | where_exp: "house", "house.rooms.value < 3" %}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 -%}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 -%}Returns the first item in the input list
If the input is not a list, it will be returned without modification.
{% var input = 'a,b,c,d' | split:',' %}first
{{input | first}}a
last
{{input | last}}d
square bracket
{{input[2]}}c
[{{input[5]}}][]
{{input[-1]}}d
{%- datastore_items var featured_houses = datastore:"houses" query:"is_featured = true" -%}
{%- datastore_items var houses_by_folder = datastore:"houses" folder:entity.folder -%}Concatenate and uniq the easy way
{% datastore_items var houses = featured_houses houses_by_folder unique %}Concatenate manually
{% var houses = featured_houses | concat: houses_by_folder %}Unique manually
{% var houses = houses | uniq %}Get one random item from the list
{% var random_house = houses | rand %}Get a random item from the list. Prevents the page from being fast-cached, and every time the page is loaded a new random item will be chosen.
Get one random item from the list and allow fast-caching
{% var random_house = houses | rand:1, false, false %}Get a random item from the list and allow the page to be fast-cached, resulting in much faster pageload speeds but the same random item will be used until the fast cache expires.
Sort the full list randomly
{% set houses = houses | shuffle %}Sort the full list randomly. The page will not be able to be fast-cached, and every time the page is loaded a new random order will be chosen. To allow the page to be fast-cached, pass false to the shuffle command.
Various ways to filter 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 -%}Advanced filter
{% var few_rooms = houses | where_exp: "house", "house.rooms.value < 3" %}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 -%}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 -%}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.
If the input is null it will return an empty list. If the input is not null and is not a list, it will be treated as a list with a single object.
{%- blog_posts posts = limit: 40 start: 1 sort_by: 'date_posted' sort_direction: 'desc' -%}
{%- var grouped_by_blog = posts | group_by: 'blog' -%}
{%- for group in grouped_by_blog -%}
<p>{{ group.Key.title }}: {{ group.Value | size }}</p>
{%- endfor -%}<p>General Blog: 22</p> <p>Announcements: 10</p> <p>Events: 8</p>
{%- datastore_items var featured_houses = datastore:"houses" query:"is_featured = true" -%}
{%- datastore_items var houses_by_folder = datastore:"houses" folder:entity.folder -%}Concatenate and uniq the easy way
{% datastore_items var houses = featured_houses houses_by_folder unique %}Concatenate manually
{% var houses = featured_houses | concat: houses_by_folder %}Unique manually
{% var houses = houses | uniq %}Get one random item from the list
{% var random_house = houses | rand %}Get a random item from the list. Prevents the page from being fast-cached, and every time the page is loaded a new random item will be chosen.
Get one random item from the list and allow fast-caching
{% var random_house = houses | rand:1, false, false %}Get a random item from the list and allow the page to be fast-cached, resulting in much faster pageload speeds but the same random item will be used until the fast cache expires.
Sort the full list randomly
{% set houses = houses | shuffle %}Sort the full list randomly. The page will not be able to be fast-cached, and every time the page is loaded a new random order will be chosen. To allow the page to be fast-cached, pass false to the shuffle command.
Various ways to filter 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 -%}Advanced filter
{% var few_rooms = houses | where_exp: "house", "house.rooms.value < 3" %}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 -%}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 -%}Returns the 0-based index of the first occurrence of find in the current list or string, or -1 if it cannot be found. If start is greater than 0, the search will begin at the specified index.
If the input is a string, will search for the index of find as a string in the input. If the input is a list, will search for the index of find in the list. If the input is neither a list or an object, the index filter will return 0 if find is the same as the input or -1 if it is not the same.
{% var list = "abcabcd" | split %}index
{{ list | index: "a" }}0
{{ list | index: "c" }}2
{{ list | index: "A" }}-1
{{ list | index: "a", 1 }}3
{{ list | index: "A", 1, true }}0
last_index
{{ list | last_index: "a" }}3
{{ list | last_index: "a", 2 }}0
{{ list | last_index: "A" }}-1
{{ list | last_index: "A", -1, true }}3
Returns the 0-based location of the find string in the current string, or -1 if it cannot be found. If start is greater than 0, the search will begin at the specified index. To ignore capitalization, set ignorecase to true.
{% var input = 'ABC About' %}index: first occurrence
{{input | index: 'A'}}0
index: start after position
{{input | index: 'A', 1}}4
index: substring
{{input | index: 'Ab'}}4
index: with case-insensitive flag
{{input | index: 'Ab', 0, true}}0
index: not found
{{input | index: 'D'}}-1
last_index: last occurrence
{{input | last_index: 'A'}}4
last_index: search backward from position
{{input | last_index: 'A', 3}}0
last_index: substring
{{input | last_index: 'AB'}}0
last_index: with case-insensitive flag
{{input | last_index: 'AB', -1, true}}4
last_index: not found
{{input | last_index: 'a'}}-1
Returns a string with each element from the input list joined together with the glue string between elements.
If the input is not a list, it will be treated as a list with a single object. If either is null, it will be treated as an empty list. All objects in the list will be converted to a string using their default string output if they are not already strings.
{% "a" | concat:"b" | json_encode %}["a", "b"]
{{ "abcdefg" | split | join }}a b c d e f g
{{ "abcdefg" | split | join:',' }}a,b,c,d,e,f,g
{%- var list = null -%}
{%- for i in (1..5) -%}
{%- set list = list | concat: i -%}
{%- endfor -%}
{{- list | join: ' and ' }}1 and 2 and 3 and 4 and 5
{%- templates templates = path:'/examples/dynamically_included' sort_by: 'name' sort_direction:'desc' -%}
<div class="primary">{{ templates | join: '</div><div class="secondary">' }}</div><div class="primary">... output from first template</div><div class="secondary">... output from second template</div><div class="secondary">... output from third template, etc...</div>
{%- datastore_items var featured_houses = datastore:"houses" query:"is_featured = true" -%}
{%- datastore_items var houses_by_folder = datastore:"houses" folder:entity.folder -%}Concatenate and uniq the easy way
{% datastore_items var houses = featured_houses houses_by_folder unique %}Concatenate manually
{% var houses = featured_houses | concat: houses_by_folder %}Unique manually
{% var houses = houses | uniq %}Get one random item from the list
{% var random_house = houses | rand %}Get a random item from the list. Prevents the page from being fast-cached, and every time the page is loaded a new random item will be chosen.
Get one random item from the list and allow fast-caching
{% var random_house = houses | rand:1, false, false %}Get a random item from the list and allow the page to be fast-cached, resulting in much faster pageload speeds but the same random item will be used until the fast cache expires.
Sort the full list randomly
{% set houses = houses | shuffle %}Sort the full list randomly. The page will not be able to be fast-cached, and every time the page is loaded a new random order will be chosen. To allow the page to be fast-cached, pass false to the shuffle command.
Various ways to filter 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 -%}Advanced filter
{% var few_rooms = houses | where_exp: "house", "house.rooms.value < 3" %}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 -%}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 -%}Return a new list with the given property from every object in the input list.
If the input is null, it will be treated as an empty list. If it is not null and not a list, it will be treated as a list with a single object.
{%- blog_posts posts = limit: 10 sort_by: 'post_date' sort_direction:'desc' -%}
{{- posts | map: 'linked_title' | join: '<br />' }}{%- datastore_items var featured_houses = datastore:"houses" query:"is_featured = true" -%}
{%- datastore_items var houses_by_folder = datastore:"houses" folder:entity.folder -%}Concatenate and uniq the easy way
{% datastore_items var houses = featured_houses houses_by_folder unique %}Concatenate manually
{% var houses = featured_houses | concat: houses_by_folder %}Unique manually
{% var houses = houses | uniq %}Get one random item from the list
{% var random_house = houses | rand %}Get a random item from the list. Prevents the page from being fast-cached, and every time the page is loaded a new random item will be chosen.
Get one random item from the list and allow fast-caching
{% var random_house = houses | rand:1, false, false %}Get a random item from the list and allow the page to be fast-cached, resulting in much faster pageload speeds but the same random item will be used until the fast cache expires.
Sort the full list randomly
{% set houses = houses | shuffle %}Sort the full list randomly. The page will not be able to be fast-cached, and every time the page is loaded a new random order will be chosen. To allow the page to be fast-cached, pass false to the shuffle command.
Various ways to filter 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 -%}Advanced filter
{% var few_rooms = houses | where_exp: "house", "house.rooms.value < 3" %}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 -%}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 -%}Returns a random value. Can behave differently depending on both the type of input and on the arguments supplied. Unless prevent_cache is false, the rand filter will prevent the page from being fast-cached. Note: the rand filter should NOT be considered cryptographically secure - do not use in places where cryptographic security is a requirement (ie: do not use to generate random passwords).
This filter behaves differently depending on the type of input supplied:
Number - If the input is an integer and length is 1, returns a new integer between 1 and the input value. If the input is an integer and length is greater than 1, returns a new list of length numbers between 1 and the input value. If allow_repeats is false, the list returned will be unique. This may result in a list with fewer than length items if the input is less than length.
String - If the input is a string, returns a new random string with length characters, where each character comes directly from the input. If allow_repeats is false, no characters from the input will be used more than once (although any character repeated in the input may be repeated up to the same number of times in the resulting string) - which may result in a string shorter than length if the input string is shorter than length.
List - If the input is a list or list-like object and length is 1, returns a random object from the list. If the input is a list or list-like object and length is greater than 1, returns a new random list of length items from the input list. If allow_repeats is false, no items from the input will be used more than once (although any repeated items in the input may be repeated up to the same number of times in the resulting list) - which may result in a list with fewer than length items if the input list has fewer than length items.
One random item from an existing list (prevents fast-caching)
{%- blog_posts posts = start:1 limit:10 -%}
{%- var randompost = posts | rand -%}
<p>Random pick: {{ randompost.linked_title }}</p>Get a random item from an existing list. Every time the page is loaded a new random item will be chosen.
One random item from an existing list (allows fast-caching)
{%- blog_posts posts = start:1 limit:10 -%}
{%- var randompost = posts | rand:1, false, false -%}
<p>Fast-Cached Random pick: {{ randompost.linked_title }}</p>Get a random item from an existing list and allow the page to be fast-cached. Subsequent pageloads will have the same random item chosen until the cache expires unless there is something else on the page that prevents fast-caching.
Improved: Fetch only one item from the database
{%- blog_posts intermediate = limit:1 sort_by:'random' cache_random:true -%}
{%- var randompost = intermediate | first -%}
<p>Today's pick: {{ randompost.linked_title }}</p>Functionally equivalent to the previous example, but only one item has to be fetched from the database. With the cache_random:true argument the result may be fast-cached and can be reused for subsequent pageloads and without the cache_random argument the page will not able to be fast-cached.
Multiple random items, no duplicates
{%- var numbers = (10..20) -%}
{%- var randomitems = numbers | rand:3, false -%}
{{- randomitems | join:' ' -}}Get 3 random numbers between 10 and 20 without repeats and outputs them as a space-separated list. Because the third argument is not provided the page will not be fast-cached and every pageload will have a new set of random numbers.
Multiple random numbers with duplicates allowed
{%- var rolls = 6 | rand: 4 -%}
<p>Dice rolls: {{ rolls | join: ', ' }}</p>Get 4 random numbers between 1 and 6 and output them as a comma-separated list. Because the second argument is not provided, duplicates are allowed. Because the third argument is not provided, the page will not be fast-cached and every pageload will have a new set of random numbers.
Multiple random numbers with duplicates allowed and fast-cacheable
{%- var rolls = 6 | rand: 4, true, false -%}
<p>Dice rolls: {{ rolls | join: ', ' }}</p>Functionally identical to the previous example except the page may be fast-cached so that future pageloads are significantly faster, but may include the same set of random numbers until the cache expires.
Multiple unique random numbers
{%- var picks = 10 | rand: 4, false -%}
<p>Unique picks: {{ picks | join: ' ' }}</p>Gets 4 unique random numbers between 1 and 10 and outputs them as a space-separated list. Because the third argument is not provided, the page will not be fast-cached and every pageload will have a new set of random numbers.
Single random number between 0 and 10
{{ 11 | rand: 1 | minus: 1 }}To get a random number starting with 0 we need to subtract 1 from the result. To allow the page to be fast-cached: Specify either true or false for the second argument (it doesn't matter which for this example) and specify false for the third argument.
Random character from a string (cache in page)
{{ "aaabcdeeefghjkmnpqrstuuuvwxyz123456789-_" | rand }}Gets a single random character from the set of characters in the string. In this example, the set of characters includes lowercase letters, numbers, and the hyphen and underscore characters with some characters excluded and some repeated to increase their probability of being chosen.
Random alphanumeric string
{{ "abcdefghijklmnopqrstuvwxyz0123456789" | rand: 10 }}Pick 10 random characters from the set, with duplicates allowed. Because the third argument is not provided, the page will not be fast-cached and every pageload will have a new set of random characters.
Random alphanumeric string without duplciates
{{ "abcdefghijklmnopqrstuvwxyz0123456789-----_____" | rand: 10, false }}Pick 10 random characters from the set, with no duplicates allowed. However, because the set itself contains 5 hyphens and 5 underscores the result may also contain up to 5 hyphens and 5 underscores. Because the third argument is provided as false, the page will not be fast-cached and every pageload will have a new set of random characters.
{%- datastore_items var featured_houses = datastore:"houses" query:"is_featured = true" -%}
{%- datastore_items var houses_by_folder = datastore:"houses" folder:entity.folder -%}Concatenate and uniq the easy way
{% datastore_items var houses = featured_houses houses_by_folder unique %}Concatenate manually
{% var houses = featured_houses | concat: houses_by_folder %}Unique manually
{% var houses = houses | uniq %}Get one random item from the list
{% var random_house = houses | rand %}Get a random item from the list. Prevents the page from being fast-cached, and every time the page is loaded a new random item will be chosen.
Get one random item from the list and allow fast-caching
{% var random_house = houses | rand:1, false, false %}Get a random item from the list and allow the page to be fast-cached, resulting in much faster pageload speeds but the same random item will be used until the fast cache expires.
Sort the full list randomly
{% set houses = houses | shuffle %}Sort the full list randomly. The page will not be able to be fast-cached, and every time the page is loaded a new random order will be chosen. To allow the page to be fast-cached, pass false to the shuffle command.
Various ways to filter 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 -%}Advanced filter
{% var few_rooms = houses | where_exp: "house", "house.rooms.value < 3" %}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 -%}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 -%}Returns the length of the input string or list.
If the input is not a string or list returns 0.
When used on null input
{{null | size}}0
When used on a string
{{"string" | size}}6
When used on a list
{{"item1,item2,item3" | split:"," | size}}3
When used on anything else
{{request.date | size}}0
{%- datastore_items var featured_houses = datastore:"houses" query:"is_featured = true" -%}
{%- datastore_items var houses_by_folder = datastore:"houses" folder:entity.folder -%}Concatenate and uniq the easy way
{% datastore_items var houses = featured_houses houses_by_folder unique %}Concatenate manually
{% var houses = featured_houses | concat: houses_by_folder %}Unique manually
{% var houses = houses | uniq %}Get one random item from the list
{% var random_house = houses | rand %}Get a random item from the list. Prevents the page from being fast-cached, and every time the page is loaded a new random item will be chosen.
Get one random item from the list and allow fast-caching
{% var random_house = houses | rand:1, false, false %}Get a random item from the list and allow the page to be fast-cached, resulting in much faster pageload speeds but the same random item will be used until the fast cache expires.
Sort the full list randomly
{% set houses = houses | shuffle %}Sort the full list randomly. The page will not be able to be fast-cached, and every time the page is loaded a new random order will be chosen. To allow the page to be fast-cached, pass false to the shuffle command.
Various ways to filter 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 -%}Advanced filter
{% var few_rooms = houses | where_exp: "house", "house.rooms.value < 3" %}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 -%}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 -%}Remove all duplicate objects in the input list. If property is specified, objects are considered duplicate if their property value is the same.
If the input is null it will return an empty list. If the input is not null and is not a list, it will be treated as a list with a single object.
{{'bookkeeper' | split: '' | uniq}}bokepr
{{'A B c d a b c' | split: ' ' | uniq}}ABcdab
{{'A B c d a b c' | split: ' ' | uniq: null, true}}ABcd
Unique by property
{%- blog_posts posts = limit:20 sort_by:'date_posted' sort_direction:'desc' -%}
{%- var latest_by_blog = posts | uniq:'blog_guid' -%}Unique by property
{% var one_per_category = items | unique:'category', true %}{%- datastore_items var featured_houses = datastore:"houses" query:"is_featured = true" -%}
{%- datastore_items var houses_by_folder = datastore:"houses" folder:entity.folder -%}Concatenate and uniq the easy way
{% datastore_items var houses = featured_houses houses_by_folder unique %}Concatenate manually
{% var houses = featured_houses | concat: houses_by_folder %}Unique manually
{% var houses = houses | uniq %}Get one random item from the list
{% var random_house = houses | rand %}Get a random item from the list. Prevents the page from being fast-cached, and every time the page is loaded a new random item will be chosen.
Get one random item from the list and allow fast-caching
{% var random_house = houses | rand:1, false, false %}Get a random item from the list and allow the page to be fast-cached, resulting in much faster pageload speeds but the same random item will be used until the fast cache expires.
Sort the full list randomly
{% set houses = houses | shuffle %}Sort the full list randomly. The page will not be able to be fast-cached, and every time the page is loaded a new random order will be chosen. To allow the page to be fast-cached, pass false to the shuffle command.
Various ways to filter 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 -%}Advanced filter
{% var few_rooms = houses | where_exp: "house", "house.rooms.value < 3" %}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 -%}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 -%}Returns the last item in the input list
If the input is not a list, it will be returned without modification.
{% var input = 'a,b,c,d' | split:',' %}first
{{input | first}}a
last
{{input | last}}d
square bracket
{{input[2]}}c
[{{input[5]}}][]
{{input[-1]}}d
Returns the last 0-based location of the last occurrence of find string in the current string, or -1 if it cannot be found. If start is greater than or equal to 0, the search will begin at the specified index. To ignore capitalization, set ignorecase to true.
{% var input = 'ABC About' %}index: first occurrence
{{input | index: 'A'}}0
index: start after position
{{input | index: 'A', 1}}4
index: substring
{{input | index: 'Ab'}}4
index: with case-insensitive flag
{{input | index: 'Ab', 0, true}}0
index: not found
{{input | index: 'D'}}-1
last_index: last occurrence
{{input | last_index: 'A'}}4
last_index: search backward from position
{{input | last_index: 'A', 3}}0
last_index: substring
{{input | last_index: 'AB'}}0
last_index: with case-insensitive flag
{{input | last_index: 'AB', -1, true}}4
last_index: not found
{{input | last_index: 'a'}}-1
Returns the 0-based index of the last occurrence of find object in the current list or string, or -1 if it cannot be found. If start is greater than -1, the search will begin at the specified index.
If the input is a string, will search for the last index of find as a string in the input. If the input is a list, will search for the last index of find in the list. If the input is neither a list or an object, the index filter will return 0 if find is the same as the input or -1 if it is not the same.
{% var list = "abcabcd" | split %}index
{{ list | index: "a" }}0
{{ list | index: "c" }}2
{{ list | index: "A" }}-1
{{ list | index: "a", 1 }}3
{{ list | index: "A", 1, true }}0
last_index
{{ list | last_index: "a" }}3
{{ list | last_index: "a", 2 }}0
{{ list | last_index: "A" }}-1
{{ list | last_index: "A", -1, true }}3
Reverses the input string or list.
When used with a string as input, the result is a string. Otherwise the result is a list.
When used on null input
{{null | reverse | object_type}}null
When used on a string
{{"string" | reverse}}gnirts
When used on a list
{{"item1,item2,item3" | split:"," | reverse | join:" "}}item3 item2 item1
Sorts the input list randomly. Unless prevent_cache is false, the shuffle filter will prevent the page from being fast-cached.
If the input is null it will return an empty list. If the input is not null and is not a list, it will be treated as a list with a single object.
{%- var stringinputs = 'JucLPXeHBgaZokTRsymNqwFViD' | split: '' -%}
{%- var numberinputs = (1..10) | shuffle -%}
{{- numberinputs | json_encode }}[7,6,5,9,2,3,8,1,10,4]
Sort strings
{{ stringinputs | sort | join: '' }}BDFHJLNPRTVXZacegikmoqsuwy
The sort filter sorts the strings in ascending order, with capital letters coming before lowercase letters.
Sort and ignore case
{{ stringinputs | sort: null, true | join: '' }}aBcDeFgHiJkLmNoPqRsTuVwXyZ
By passing true as the second argument, the sort filter will ignore capitalization when comparing strings.
Sort and ignore case using sort_natural
{{ stringinputs | sort_natural | join: '' }}aBcDeFgHiJkLmNoPqRsTuVwXyZ
The sort_natural filter is the same as the sort filter with the second argument set to true.
Sort numbers
{{ numberinputs | sort | join: ' ' }}1 2 3 4 5 6 7 8 9 10
The sort filter sorts the numbers in ascending order.
Sort objects
{% var sorted = houses | sort: 'number_of_rooms' %}To sort objects, pass in the property to sort by. In this example, the list of houses will be sorted by the "number_of_rooms" property.
Sort objects by string property and ignore case
{% var sorted = houses | sort: 'name', true %}When sorting objects by a string property, remember to set the second argument to true or else uppercase letters will be sorted higher before lowercase letters.
Sort randomly
{{ stringinputs | shuffle | join: '' }}JDgRoPNTFckXsmBHZqawVeyuLi
The shuffle filter sorts the strings in a random order. The page will not be able to be fast-cached, and every time the page is loaded a new random order will be chosen.
Sort randomly and allow fast-caching
{{ stringinputs | shuffle: false | join: '' }}kjFQDXZTVgEruhPbHnCwIYMzASO
Pass false to the shuffle command to specify that the page may still be fast-cached, resulting in much faster pageload times but the same random result will be chosen on every pageload until the fast cache expires.
Sort randomly using the sort filter with the special string "random" as the property
{{ numberinputs | sort: 'random' | join }}9 5 4 10 6 2 1 3 7 8
Passing "random" as the first argument to the sort filter is functionally identical to using the shuffle filter. In most cases, the shuffle filter should be preferred for clarity.
{%- datastore_items var featured_houses = datastore:"houses" query:"is_featured = true" -%}
{%- datastore_items var houses_by_folder = datastore:"houses" folder:entity.folder -%}Concatenate and uniq the easy way
{% datastore_items var houses = featured_houses houses_by_folder unique %}Concatenate manually
{% var houses = featured_houses | concat: houses_by_folder %}Unique manually
{% var houses = houses | uniq %}Get one random item from the list
{% var random_house = houses | rand %}Get a random item from the list. Prevents the page from being fast-cached, and every time the page is loaded a new random item will be chosen.
Get one random item from the list and allow fast-caching
{% var random_house = houses | rand:1, false, false %}Get a random item from the list and allow the page to be fast-cached, resulting in much faster pageload speeds but the same random item will be used until the fast cache expires.
Sort the full list randomly
{% set houses = houses | shuffle %}Sort the full list randomly. The page will not be able to be fast-cached, and every time the page is loaded a new random order will be chosen. To allow the page to be fast-cached, pass false to the shuffle command.
Various ways to filter 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 -%}Advanced filter
{% var few_rooms = houses | where_exp: "house", "house.rooms.value < 3" %}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 -%}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 -%}Return a part of the current string or list.
If the input is a string this will return a string. If it is a list it will return a list. Otherwise it will not do anything and will return the unaltered input.
When used on null input
{{null | slice | object_type}}null
When used on a string
{{"string" | slice: 2}}ring
{{"string" | slice: 2, 3}}rin
When used on a list
{{"ab,cd,ef,gh,ij,kl,mn,op,qr,st,uv,wx,yz" | split:"," | slice: 2, 3 | join: " "}}ef gh ij
With a negative start value
{{"string" | slice: -2}}ng
With a negative length
{{"string" | slice: 2, -1}}rin
With a negative start and length
{{"string" | slice: -4, -2}}ri
With length = 0
{{"string" | slice: -4, 0}}ring
With a really large negative start
{{"string" | slice: -20}}string
With start higher than the input length
[{{"string" | slice: 20}}][]
With a calculated length less or equal to 0
[{{"string" | slice: 2, -4}}][]
Does not do anything if the object is not a string or a list
{{ request.date | slice: 2 }}9/9/2009 12:00:00 AM
{%- datastore_items var featured_houses = datastore:"houses" query:"is_featured = true" -%}
{%- datastore_items var houses_by_folder = datastore:"houses" folder:entity.folder -%}Concatenate and uniq the easy way
{% datastore_items var houses = featured_houses houses_by_folder unique %}Concatenate manually
{% var houses = featured_houses | concat: houses_by_folder %}Unique manually
{% var houses = houses | uniq %}Get one random item from the list
{% var random_house = houses | rand %}Get a random item from the list. Prevents the page from being fast-cached, and every time the page is loaded a new random item will be chosen.
Get one random item from the list and allow fast-caching
{% var random_house = houses | rand:1, false, false %}Get a random item from the list and allow the page to be fast-cached, resulting in much faster pageload speeds but the same random item will be used until the fast cache expires.
Sort the full list randomly
{% set houses = houses | shuffle %}Sort the full list randomly. The page will not be able to be fast-cached, and every time the page is loaded a new random order will be chosen. To allow the page to be fast-cached, pass false to the shuffle command.
Various ways to filter 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 -%}Advanced filter
{% var few_rooms = houses | where_exp: "house", "house.rooms.value < 3" %}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 -%}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 -%}Sort objects in the input list. If the property is specified, use it to sort objects in the list. Use the special string value "random" to sort the list in a random order - which is functionally identical to using the shuffle filter.
If the input is null it will return an empty list. If the input is not null and is not a list, it will be treated as a list with a single object.
{%- var stringinputs = 'JucLPXeHBgaZokTRsymNqwFViD' | split: '' -%}
{%- var numberinputs = (1..10) | shuffle -%}
{{- numberinputs | json_encode }}[7,6,5,9,2,3,8,1,10,4]
Sort strings
{{ stringinputs | sort | join: '' }}BDFHJLNPRTVXZacegikmoqsuwy
The sort filter sorts the strings in ascending order, with capital letters coming before lowercase letters.
Sort and ignore case
{{ stringinputs | sort: null, true | join: '' }}aBcDeFgHiJkLmNoPqRsTuVwXyZ
By passing true as the second argument, the sort filter will ignore capitalization when comparing strings.
Sort and ignore case using sort_natural
{{ stringinputs | sort_natural | join: '' }}aBcDeFgHiJkLmNoPqRsTuVwXyZ
The sort_natural filter is the same as the sort filter with the second argument set to true.
Sort numbers
{{ numberinputs | sort | join: ' ' }}1 2 3 4 5 6 7 8 9 10
The sort filter sorts the numbers in ascending order.
Sort objects
{% var sorted = houses | sort: 'number_of_rooms' %}To sort objects, pass in the property to sort by. In this example, the list of houses will be sorted by the "number_of_rooms" property.
Sort objects by string property and ignore case
{% var sorted = houses | sort: 'name', true %}When sorting objects by a string property, remember to set the second argument to true or else uppercase letters will be sorted higher before lowercase letters.
Sort randomly
{{ stringinputs | shuffle | join: '' }}JDgRoPNTFckXsmBHZqawVeyuLi
The shuffle filter sorts the strings in a random order. The page will not be able to be fast-cached, and every time the page is loaded a new random order will be chosen.
Sort randomly and allow fast-caching
{{ stringinputs | shuffle: false | join: '' }}kjFQDXZTVgEruhPbHnCwIYMzASO
Pass false to the shuffle command to specify that the page may still be fast-cached, resulting in much faster pageload times but the same random result will be chosen on every pageload until the fast cache expires.
Sort randomly using the sort filter with the special string "random" as the property
{{ numberinputs | sort: 'random' | join }}9 5 4 10 6 2 1 3 7 8
Passing "random" as the first argument to the sort filter is functionally identical to using the shuffle filter. In most cases, the shuffle filter should be preferred for clarity.
{%- datastore_items var featured_houses = datastore:"houses" query:"is_featured = true" -%}
{%- datastore_items var houses_by_folder = datastore:"houses" folder:entity.folder -%}Concatenate and uniq the easy way
{% datastore_items var houses = featured_houses houses_by_folder unique %}Concatenate manually
{% var houses = featured_houses | concat: houses_by_folder %}Unique manually
{% var houses = houses | uniq %}Get one random item from the list
{% var random_house = houses | rand %}Get a random item from the list. Prevents the page from being fast-cached, and every time the page is loaded a new random item will be chosen.
Get one random item from the list and allow fast-caching
{% var random_house = houses | rand:1, false, false %}Get a random item from the list and allow the page to be fast-cached, resulting in much faster pageload speeds but the same random item will be used until the fast cache expires.
Sort the full list randomly
{% set houses = houses | shuffle %}Sort the full list randomly. The page will not be able to be fast-cached, and every time the page is loaded a new random order will be chosen. To allow the page to be fast-cached, pass false to the shuffle command.
Various ways to filter 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 -%}Advanced filter
{% var few_rooms = houses | where_exp: "house", "house.rooms.value < 3" %}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 -%}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 -%}Sort objects in the input list. If the property is specified, use it to sort objects in the list. Use the special string value "random" to sort the list in a random order - which is functionally identical to using the shuffle filter. The sort_natural filter ignores capitalization while the sort filter does not by default. For readability and consistency, it is advised to use the sort filter with the ignorecase property set to true instead of the sort_natural filter.
If the input is null it will return an empty list. If the input is not null and is not a list, it will be treated as a list with a single object.
{%- var stringinputs = 'JucLPXeHBgaZokTRsymNqwFViD' | split: '' -%}
{%- var numberinputs = (1..10) | shuffle -%}
{{- numberinputs | json_encode }}[7,6,5,9,2,3,8,1,10,4]
Sort strings
{{ stringinputs | sort | join: '' }}BDFHJLNPRTVXZacegikmoqsuwy
The sort filter sorts the strings in ascending order, with capital letters coming before lowercase letters.
Sort and ignore case
{{ stringinputs | sort: null, true | join: '' }}aBcDeFgHiJkLmNoPqRsTuVwXyZ
By passing true as the second argument, the sort filter will ignore capitalization when comparing strings.
Sort and ignore case using sort_natural
{{ stringinputs | sort_natural | join: '' }}aBcDeFgHiJkLmNoPqRsTuVwXyZ
The sort_natural filter is the same as the sort filter with the second argument set to true.
Sort numbers
{{ numberinputs | sort | join: ' ' }}1 2 3 4 5 6 7 8 9 10
The sort filter sorts the numbers in ascending order.
Sort objects
{% var sorted = houses | sort: 'number_of_rooms' %}To sort objects, pass in the property to sort by. In this example, the list of houses will be sorted by the "number_of_rooms" property.
Sort objects by string property and ignore case
{% var sorted = houses | sort: 'name', true %}When sorting objects by a string property, remember to set the second argument to true or else uppercase letters will be sorted higher before lowercase letters.
Sort randomly
{{ stringinputs | shuffle | join: '' }}JDgRoPNTFckXsmBHZqawVeyuLi
The shuffle filter sorts the strings in a random order. The page will not be able to be fast-cached, and every time the page is loaded a new random order will be chosen.
Sort randomly and allow fast-caching
{{ stringinputs | shuffle: false | join: '' }}kjFQDXZTVgEruhPbHnCwIYMzASO
Pass false to the shuffle command to specify that the page may still be fast-cached, resulting in much faster pageload times but the same random result will be chosen on every pageload until the fast cache expires.
Sort randomly using the sort filter with the special string "random" as the property
{{ numberinputs | sort: 'random' | join }}9 5 4 10 6 2 1 3 7 8
Passing "random" as the first argument to the sort filter is functionally identical to using the shuffle filter. In most cases, the shuffle filter should be preferred for clarity.
Multiply the input by the operand.
This filter currently behaves differently if the input is a string and the operand is an integer. In that case the result is a list of strings with input repeated operand times.
Current functionality
{{"string" | times:2 | json_encode}}["string","string"]
Future functionality
{{"string" | times:2 | json_encode}}Liquid error
Potential Replacement
{%- map string for i in (1..2) %}string{% endmap -%}
{{-string | json_encode}}["string","string"]
Alternate Replacement
{%- capture string %}{% for i in (1..2) %}string{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture -%}
{{-string | split:',' | json_encode}}["string","string"]
Split a string into a list of substrings separated by the given separator
{{'bookkeeper' | split: '' | uniq}}bokepr
{{'A B c d a b c' | split: ' ' | uniq}}ABcdab
{{'A B c d a b c' | split: ' ' | uniq: null, true}}ABcd
Unique by property
{%- blog_posts posts = limit:20 sort_by:'date_posted' sort_direction:'desc' -%}
{%- var latest_by_blog = posts | uniq:'blog_guid' -%}Unique by property
{% var one_per_category = items | unique:'category', true %}{% var list = "abcabcd" | split %}index
{{ list | index: "a" }}0
{{ list | index: "c" }}2
{{ list | index: "A" }}-1
{{ list | index: "a", 1 }}3
{{ list | index: "A", 1, true }}0
last_index
{{ list | last_index: "a" }}3
{{ list | last_index: "a", 2 }}0
{{ list | last_index: "A" }}-1
{{ list | last_index: "A", -1, true }}3
{{'The quick brown fox jumps over the lazy dog.' | split:" " | json_encode}}["The","quick","brown","fox","jumps","over","the","lazy","dog."]
Split on multiple characters
{{'She sells sea shells on the sea shore.' | split:"sea" | json_encode}}["She sells "," shells on the "," shore."]
Does not include empty strings in the result
{{"110100101" | split:'1' | json_encode}}["0","00","0" | split:'1'}}
Use an empty pattern to split the string into individual characters
{{"abcdef" | split:'' | json_encode}}["a","b","c","d","e","f"]
Returns a new list which only contains items from the input list where the property has the specified value.
If the input is null it will return an empty list. If the input is not null and is not a list, it will be treated as a list with a single object. If the property to filter by is null, the input list will be unfiltered.
{% var arr = existing_list | where: 'priority', 1 %}{% var arr = existing_list | where: 'position', 'top', true %}{% var with_rooms = houses | where_exp: 'house', 'house.rooms.value >= 2' %}{%- datastore_items var featured_houses = datastore:"houses" query:"is_featured = true" -%}
{%- datastore_items var houses_by_folder = datastore:"houses" folder:entity.folder -%}Concatenate and uniq the easy way
{% datastore_items var houses = featured_houses houses_by_folder unique %}Concatenate manually
{% var houses = featured_houses | concat: houses_by_folder %}Unique manually
{% var houses = houses | uniq %}Get one random item from the list
{% var random_house = houses | rand %}Get a random item from the list. Prevents the page from being fast-cached, and every time the page is loaded a new random item will be chosen.
Get one random item from the list and allow fast-caching
{% var random_house = houses | rand:1, false, false %}Get a random item from the list and allow the page to be fast-cached, resulting in much faster pageload speeds but the same random item will be used until the fast cache expires.
Sort the full list randomly
{% set houses = houses | shuffle %}Sort the full list randomly. The page will not be able to be fast-cached, and every time the page is loaded a new random order will be chosen. To allow the page to be fast-cached, pass false to the shuffle command.
Various ways to filter 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 -%}Advanced filter
{% var few_rooms = houses | where_exp: "house", "house.rooms.value < 3" %}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 -%}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 -%}Returns a new list which only contains items from the input list that match the given expression when the item is referenced as name.
If the input is null it will return an empty list. If the input is not null and is not a list, it will be treated as a list with a single object. If either name or expression are null or empty, the input list will be unfiltered.
{% var arr = existing_list | where: 'priority', 1 %}{% var arr = existing_list | where: 'position', 'top', true %}{% var with_rooms = houses | where_exp: 'house', 'house.rooms.value >= 2' %}{%- datastore_items var featured_houses = datastore:"houses" query:"is_featured = true" -%}
{%- datastore_items var houses_by_folder = datastore:"houses" folder:entity.folder -%}Concatenate and uniq the easy way
{% datastore_items var houses = featured_houses houses_by_folder unique %}Concatenate manually
{% var houses = featured_houses | concat: houses_by_folder %}Unique manually
{% var houses = houses | uniq %}Get one random item from the list
{% var random_house = houses | rand %}Get a random item from the list. Prevents the page from being fast-cached, and every time the page is loaded a new random item will be chosen.
Get one random item from the list and allow fast-caching
{% var random_house = houses | rand:1, false, false %}Get a random item from the list and allow the page to be fast-cached, resulting in much faster pageload speeds but the same random item will be used until the fast cache expires.
Sort the full list randomly
{% set houses = houses | shuffle %}Sort the full list randomly. The page will not be able to be fast-cached, and every time the page is loaded a new random order will be chosen. To allow the page to be fast-cached, pass false to the shuffle command.
Various ways to filter 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 -%}Advanced filter
{% var few_rooms = houses | where_exp: "house", "house.rooms.value < 3" %}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 -%}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 -%}