Liquid Filters

Filters may be used to modify the output of objects before either being stored in a variable or output to the page. Filters should be used as "expression | filter_name:filterParam1, filterParam2, etc..." (eg: {{ request.date | inspect: 2, true }}, or {% assign end_date = request.date | add_weeks:1 %}).

Multiple filters may be applied to an object at the same time and are processed in the same order that they appear in the markup. Eg: {% assign my_date = request.date | midnight | add_hours:3 %} will result in a different date than {% assign my_date = request.date | add_hours:3 | midnight %}

Utility Filters

Number Filters

plus filter

Adds the operand to the current value. Note that this filter behaves differently if the current value is a string

plus: Number operand

Examples

Add some numbers together

Copy
3+5 = {{3 | plus: 5}} -4.2+2.1 = {{-4.2 | plus: 2.1}}

times filter

Multiply the input by the operand.

times: Number operand

Examples

Use the times filter to multiply a number by another number

Multiply numbers

Copy
{{4 | times:2}}
{{4.1 | times:-2.2}}

You can currently use the times to multiply a string into a list of identical strings, although this behavior is deprecated. If you need this functionality you are advised to find a different way to accomplish it.

Using the times filter with a string

Copy

Current functionality

{{"string" | times:2 | json_encode}}

Future functionality

{{"string" | times:2 | json_encode}}

Potential Replacement

{% map string for i in (1..2) %}string{% endmap -%} {{string | json_encode}}

Alternate Replacement

{% capture string %}{% for i in (1..2) %}string{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture -%} {{string | split:',' | json_encode}}

divided_by filter

Divide the input by operand.

divided_by: Number operand

Examples

Use the divided_by filter to divide one number by another.

Using the divided_by filter

Copy
{{8 | divided_by:2}}
{{13.3 | divided_by:1.4}}

modulo filter

Return the remainder of the input when divided by the operand.

modulo: Number operand

Examples

Use the modulo filter to get the remainder when one number is divided by another.

Using the modulo filter

Copy
{{5 | modulo:3}}
{{13.3 | modulo:1.4}}
{{-3 | modulo:2}}
{{3 | modulo:-2}}

minus filter

Subtracts the operand from the input.

minus: Number operand

Examples

Use the minus filter to subtract one number from another.

Using the minus filter

Copy
{{5 | minus:1}}
{{13.3 | minus:14.4}}

to_int filter

Converts the input to an integer.

to_int

Examples

Convert a query parameter to an integer value with a default value.

Convert to integer

Copy
{% var limit = request.query_params['limit'] | default: 20 | to_int %}

to_number filter

Converts the input to a number.

to_number

Examples

Convert a query parameter to a number with a default value.

Convert to number

Copy
{% var average = request.query_params['average'] | default: 2.5 | to_number %}

String Filters

append filter

Add text to the end of the input. If the input is not already a string it will be converted to one using the default behavior for its object type.

append: String text

Examples

Append text onto the end of a string

Append text

Copy
{{"fire" | append:"truck"}}

capitalize filter

Capitalize words in a string

capitalize

Examples

Capitalize all of the words in a sentance

Capitalize words in a string

Copy
{{"a freight train running through the" | capitalize}}

classname filter

Removes all non-alphanumeric characters other than dashes and underscores from a string and replaces them with the separator (or nothing if the separator is empty) to form a valid CSS classname.

classname: String separator

Examples

Three ways to use the classname filter to convert text into a valid CSS classname

Convert text to a classname

Copy
{{"a long classname!" | classname}} {{"a long classname!" | classname: "_"}} {{"a long classname!" | classname: ""}}

downcase filter

Convert a string to lowercase

downcase

Examples

Convert all characters in a string to lowercase.

Convert a string to lowercase

Copy
{{"A Freight TRAIN Running TRHOUGH THE" | downcase}}

escape filter

Encode a string to be output as HTML. All special HTML characters will be converted to their equivalent HTML character entities (eg: < becomes &lt;)

escape

Examples

Escape HTML characters in a string for output inside other HTML markup.

Escape HTML characters in a string

Copy

A string with HTML & other characters

" | escape}}">...

escape_once filter

Encode a string to be output as HTML, without changing existing escaped entities.

escape_once

Examples

Escape HTML characters in a string for output inside other HTML markup. If HTML characters have already been escaped, do not "double-escape" them.

Escape HTML characters in a string once

Copy

...

DEPRECATED for_json filter

Use the json_encode filter instead.

Encode a string to be used output as JSON. Unlike json_encode, if the string is null this will return an empty string instead.

for_json

Examples

Use the for_json filter on variables that both do and do not have values

For Json Deprecation

Copy
{"something": {{'with "value"' | for_json}} } {"something": {{null | for_json}} }

h filter (alias for escape)

Alias for escape, which encodes a string to be output as HTML. Although h is shorter, escape is preferred due to its improved readability and maintainability.

h

html_decode filter

Decodes any encoded HTML entities (eg: &lt; becomes <)

html_decode

Examples

Decode any encoded HTML entities inside a string.

Decode HTML entities in a string

Copy
{{"<p>A string with HTML & other characters</p>" | html_decode}}

html_encode filter

Encode a string to be output as HTML. All special HTML characters will be converted to their equivalent HTML character entities (eg: < becomes <). This is functionally identical to the escape filter, though it may be more intuitive in some contexts - such as when using both the html_encode and html_decode filters to execute more advanced string manipulation.

html_encode

Examples

Encode a string for output inside other HTML markup.

Encode HTML entities in a string

Copy

A string with HTML & other characters

" | html_encode}}">...

index filter

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.

index: String findInteger startBoolean ignorecase

Examples

Multiple ways to use the index filter to search for text inside a string.

Get Substring Indexes with Various Arguments

Copy
{% var input = 'ABC About' %}
{{input | index: 'A'}}
{{input | index: 'A', 1}}
{{input | index: 'Ab'}}
{{input | index: 'Ab', 0, true}}
{{input | index: 'D'}}

json_decode filter

Decode a json encoded string

json_decode

Examples

Use the json_decode filter to decode a json encoded string

Decode a json encoded string

Copy
{{'\"liquid\" filter' | json_decode}}

json_encode filter

Encode the input object to be used as a JSON property.

json_encode

Examples

Use the json_encode filter to format the input for output as json properties. While most usefulf or strings, this can also be used with other object types.

Json_encode various object types

Copy
{ "null": {{ null | for_json }}, "date": {{ request.date | json_encode }}, "true": {{ true | json_encode }}, "3": {{ 3 | json_encode }}, "-4.2": {{ -4.2 | json_encode }}, "string": {{ 'Liquid is "cool"' | json_encode }} }

last_index filter

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.

last_index: String findInteger startBoolean ignorecase

Examples

Multiple ways to use the last_index filter to search for text inside a string.

Getting the last substring indexes with various arguments

Copy
{% var input = 'ABC About' %}
{{input | last_index: 'A'}}
{{input | last_index: 'A', 3}}
{{input | last_index: 'AB'}}
{{input | last_index: 'AB', -1, true}}
{{input | last_index: 'a'}}

lstrip filter

Removes whitespace from the beginning of a string

lstrip

Examples

3 filters to remove whitespace from before and after strings

Various ways to strip whitespace from strings

Copy
{% var sentence_with_extra_whitespace = ' The quick brown fox jumps over the lazy dog. ' %}
[{{sentence_with_extra_whitespace | lstrip}}]
[{{sentence_with_extra_whitespace | rstrip}}]
[{{sentence_with_extra_whitespace | strip}}]

newline_to_br filter

Add <br /> tags in front of all newlines in the current string

newline_to_br

Examples

Add <br /> in front of all newlines in a string

Copy
{% capture input -%} ABC DEF GHI {%- endcapture -%} {{input | newline_to_br}}

plus filter

Adds the operand to the current value. Note that this filter behaves differently if the current value is a string

plus: Number operand

Examples

Add some numbers together

Copy
3+5 = {{3 | plus: 5}} -4.2+2.1 = {{-4.2 | plus: 2.1}}

prepend filter

Add text to the beginning of the input. If the input is not already a string it will be converted to one using the default behavior for its object type.

prepend: String text

Examples

Prepend text onto the beginning of a string

Prepend text

Copy
{{"truck" | prepend:"fire"}}

remove filter

Remove all occurrences of search from the current string.

remove: String search

Examples

Use the remove and remove_first filters to remove a string from another string

Remove text from the input string

Copy
{% var input = 'apply for apples app development' %}
{{input | remove:'app'}}
{{input | remove_first:'app'}}
{{input | remove_first:'app', 2}}

The remove and remove_first filters are case-sensitive

{{ input | remove:'App' }}

remove_first filter

Remove the first occurrence(s) of search from the current string.

remove_first: String searchInteger num_replacements

Examples

Use the remove and remove_first filters to remove a string from another string

Remove text from the input string

Copy
{% var input = 'apply for apples app development' %}
{{input | remove:'app'}}
{{input | remove_first:'app'}}
{{input | remove_first:'app', 2}}

The remove and remove_first filters are case-sensitive

{{ input | remove:'App' }}

replace filter

Replace all occurrences of search inside the current string with replacement

replace: String searchString replacement

Examples

Use the replace and replace_first filters to replace a string with another string inside the input

Replace text in the input string

Copy
{% var input = 'apply for apples app development' %}
{{input | replace:'app', 'mop'}}
{{input | replace_first:'app', 'mop'}}
{{input | replace_first:'app', 'mop', 2}}

The replace and replace_first filters are case-sensitive

{{ input | replace:'App', 'Mop'}}

replace_first filter

Replace the first occurrence(s) of search inside the current string with replacement

replace_first: String searchString replacementInteger num_replacements

Examples

Use the replace and replace_first filters to replace a string with another string inside the input

Replace text in the input string

Copy
{% var input = 'apply for apples app development' %}
{{input | replace:'app', 'mop'}}
{{input | replace_first:'app', 'mop'}}
{{input | replace_first:'app', 'mop', 2}}

The replace and replace_first filters are case-sensitive

{{ input | replace:'App', 'Mop'}}

replace_regex filter

Replace all occurrences of pattern inside the current string with replacement using a regular expression - making it possible to search for more complicated expressions and replace using the resulting captured groups.

replace_regex: String patternString replacement

Examples

Use the replace_regex and replace_regex_first filters to use advanced matching logic to replace a string with another string inside the input

Replace text in the input string using a regex

Copy
{% var input = 'The quick brown dog jumps over the lazy dog.' %}
{{input | replace_regex:'/dog/i', 'dragon'}}
{{input | replace_regex_first:'/dog/i', 'dragon'}}
{{input | replace_regex_first:'(quick|brown|lazy)', 'adjective:$1', 2}}

replace_regex_first filter

Replace the first occurrence(s) of pattern inside the current string with replacement using a regular expression - making it possible to search for more complicated expressions and replace using the resulting captured groups.

replace_regex_first: String patternString replacementInteger num_replacements

Examples

Use the replace_regex and replace_regex_first filters to use advanced matching logic to replace a string with another string inside the input

Replace text in the input string using a regex

Copy
{% var input = 'The quick brown dog jumps over the lazy dog.' %}
{{input | replace_regex:'/dog/i', 'dragon'}}
{{input | replace_regex_first:'/dog/i', 'dragon'}}
{{input | replace_regex_first:'(quick|brown|lazy)', 'adjective:$1', 2}}

reverse filter

Reverses the input string or list.

reverse

Examples

Use the reverse filter to reverse either a string or a list

Using the reverse filter

Copy

When used on null input

{{null | reverse | object_type}}

When used on a string

{{"string" | reverse}}

When used on a list

{{"item1,item2,item3" | split:"," | reverse | join:" "}}

rstrip filter

Removes whitespace from the end of a string

rstrip

Examples

3 filters to remove whitespace from before and after strings

Various ways to strip whitespace from strings

Copy
{% var sentence_with_extra_whitespace = ' The quick brown fox jumps over the lazy dog. ' %}
[{{sentence_with_extra_whitespace | lstrip}}]
[{{sentence_with_extra_whitespace | rstrip}}]
[{{sentence_with_extra_whitespace | strip}}]

size filter

Returns the length of the input string or list.

size

Examples

Use the size filter to get the size of a string or a list

Using the size filter

Copy

When used on null input

{{null | size}}

When used on a string

{{"string" | size}}

When used on a list

{{"item1,item2,item3" | split:"," | size}}

When used on anything else

{{request.date | size}}

slice filter

Return a part of the current string or list.

slice: Integer startInteger length

Examples

Use the slice filter to get a portion of a string or list.

Using the slice filter

Copy

When used on null input

{{null | slice | object_type}}

When used on a string

{{"string" | slice: 2}}
{{"string" | slice: 2, 3}}

When used on a list

{{"ab,cd,ef,gh,ij,kl,mn,op,qr,st,uv,wx,yz" | split:"," | slice: 2, 3 | join: " "}}

With a negative start value

{{"string" | slice: -2}}

With a negative length

{{"string" | slice: 2, -1}}

With a negative start and length

{{"string" | slice: -4, -2}}

With length = 0

{{"string" | slice: -4, 0}}

With a really large negative start

{{"string" | slice: -20}}

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 }}

split filter

Split a string into a list of substrings separated by the given separator

split: String separator

Examples

Use the split filter to convert a string into a list of strings separated by the given separator

Using the split filter

Copy
{{'The quick brown fox jumps over the lazy dog.' | split:" " | json_encode}}

Split on multiple characters

{{'She sells sea shells on the sea shore.' | split:"sea" | json_encode}}

Does not include empty strings in the result

{{"110100101" | split:'1' | json_encode}}

Use an empty pattern to split the string into individual characters

{{"abcdef" | split:'' | json_encode}}

strip filter

Removes whitespace from the beginning and end of a string

strip

Examples

3 filters to remove whitespace from before and after strings

Various ways to strip whitespace from strings

Copy
{% var sentence_with_extra_whitespace = ' The quick brown fox jumps over the lazy dog. ' %}
[{{sentence_with_extra_whitespace | lstrip}}]
[{{sentence_with_extra_whitespace | rstrip}}]
[{{sentence_with_extra_whitespace | strip}}]

strip_html filter

Removes all HTML tags from a string

strip_html

Examples

Strip HTML from an input string

Copy
{{'

The quick brown fox jumps over the lazy dog.

' | strip_html}}
{% capture input -%}

The quick brown fox jumps over the lazy dog.


note that this will also strip images {%- endcapture -%} {{input | strip_html | strip}}

Could result in unexpected behavior with poorly formatted input

{% capture input -%} //script outside of a script tag if (a < b) doSomething(); if(a > b) doSomethingElse(); //endscript {%- endcapture -%} {{input | strip_html | strip}}

Could result in unexpected behavior with poorly formatted input

{% capture input -%}

The following invalid markup contains an unescaped > character in an HTML attribute:

{%- endcapture -%} {{input | strip_html | strip}}

strip_newlines filter

Removes all newlines from a string

strip_newlines

Examples

Use the strip_newlines filter to remove all newlines from a string

Remove newlines from a string

Copy
{% capture input -%} ABC DEF GHI {%- endcapture -%} {{input | strip_newlines}}

times filter

Multiply the input by the operand.

times: Number operand

Examples

Use the times filter to multiply a number by another number

Multiply numbers

Copy
{{4 | times:2}}
{{4.1 | times:-2.2}}

You can currently use the times to multiply a string into a list of identical strings, although this behavior is deprecated. If you need this functionality you are advised to find a different way to accomplish it.

Using the times filter with a string

Copy

Current functionality

{{"string" | times:2 | json_encode}}

Future functionality

{{"string" | times:2 | json_encode}}

Potential Replacement

{% map string for i in (1..2) %}string{% endmap -%} {{string | json_encode}}

Alternate Replacement

{% capture string %}{% for i in (1..2) %}string{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture -%} {{string | split:',' | json_encode}}

truncate filter

Truncates a string down to length characters. If the original string is longer than length characters, the result will end with truncate_string.

truncate: Integer lengthString truncate_string

Examples

Use the truncate, truncate_to_word, or truncate_words filter to shorten text to a specific number of characters or words.

Truncating text

Copy
{% var input = 'The quick brown fox jumps over the lazy dog.' %}

truncate

{{input | truncate:33}}
{{input | truncate:33 | size}}
{{input | truncate:31, " (more)"}}
{{input | truncate:33, ""}}
{{'Shorter than 33 characters' | truncate: 33}}

truncate_to_word

{{input | truncate_to_word:30}}
{{input | truncate_to_word:30 | size}}
{{input | truncate_to_word:30, false}}
{{input | truncate_to_word:30, false | size}}

truncate_words

{{input | truncate_words:3}}
{{input | truncate_words:3, " (more)"}}
{{input | truncate_words:9}}

truncate_to_word filter

Truncates a string down to length characters. If the string would be broken in the middle of a word, ensures that the break happens either before or after the word. If the string is truncated it will end with truncate_string.

truncate_to_word: Integer lengthBoolean break_before_wordString truncate_string

Examples

Use the truncate, truncate_to_word, or truncate_words filter to shorten text to a specific number of characters or words.

Truncating text

Copy
{% var input = 'The quick brown fox jumps over the lazy dog.' %}

truncate

{{input | truncate:33}}
{{input | truncate:33 | size}}
{{input | truncate:31, " (more)"}}
{{input | truncate:33, ""}}
{{'Shorter than 33 characters' | truncate: 33}}

truncate_to_word

{{input | truncate_to_word:30}}
{{input | truncate_to_word:30 | size}}
{{input | truncate_to_word:30, false}}
{{input | truncate_to_word:30, false | size}}

truncate_words

{{input | truncate_words:3}}
{{input | truncate_words:3, " (more)"}}
{{input | truncate_words:9}}

truncate_words filter

Truncates the input string down to length words. If the input is longer than length words, appends truncate_string to the end of the truncated string.

truncate_words: Integer lengthString truncate_string

Examples

Use the truncate, truncate_to_word, or truncate_words filter to shorten text to a specific number of characters or words.

Truncating text

Copy
{% var input = 'The quick brown fox jumps over the lazy dog.' %}

truncate

{{input | truncate:33}}
{{input | truncate:33 | size}}
{{input | truncate:31, " (more)"}}
{{input | truncate:33, ""}}
{{'Shorter than 33 characters' | truncate: 33}}

truncate_to_word

{{input | truncate_to_word:30}}
{{input | truncate_to_word:30 | size}}
{{input | truncate_to_word:30, false}}
{{input | truncate_to_word:30, false | size}}

truncate_words

{{input | truncate_words:3}}
{{input | truncate_words:3, " (more)"}}
{{input | truncate_words:9}}

upcase filter

Convert a string to uppercase

upcase

Examples

Convert all characters in a string to uppercase.

Convert a string to uppercase

Copy
{{"A Freight TRAIN Running TRHOUGH THE" | upcase}}

url_decode filter

Decode a url encoded string.

url_decode: Boolean formdata

Examples

Use the url_encode and url_decode filters to encode strings for use in URLs, and to decode strings that have been url encoded.

Url Encoding and Decoding

Copy

url_encode

{{"liquid filter" | url_encode}}
{{"liquid filter" | url_encode:true}}

url_decode

{{"liquid%20filter" | url_decode}}
{{"liquid+filter" | url_decode}}
{{"liquid+filter" | url_decode:true}}

url_encode filter

Encode a string to be used in a URL.

url_encode: Boolean formdata

Examples

Use the url_encode and url_decode filters to encode strings for use in URLs, and to decode strings that have been url encoded.

Url Encoding and Decoding

Copy

url_encode

{{"liquid filter" | url_encode}}
{{"liquid filter" | url_encode:true}}

url_decode

{{"liquid%20filter" | url_decode}}
{{"liquid+filter" | url_decode}}
{{"liquid+filter" | url_decode:true}}

List Filters

index filter

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.

index: object findInteger startBoolean ignorecase

Examples

Use the index and last_index filters to find a specific item in a list.

Find something in a list

Copy
{% var list = "abcabcd" | split %}

index

{{ list | index: "a" }}
{{ list | index: "c" }}
{{ list | index: "A" }}
{{ list | index: "a", 1 }}
{{ list | index: "A", 1, true }}

last_index

{{ list | last_index: "a" }}
{{ list | last_index: "a", 2 }}
{{ list | last_index: "A" }}
{{ list | last_index: "A", -1, true }}

join filter

Returns a string with each element from the input list joined together with the glue string between elements.

join

Examples

Use the join filter to join a list of strings together. Items in the list that are not already strings will be converted to a string before being joined together.

Join a list into a single string

Copy
{{ "abcdefg" | split | join }}
{{ "abcdefg" | split | join:',' }}
{% var list = null %} {% for i in (1..5) %} {% set list = list | concat: i %} {% endfor %} {{ list | join: ' and ' }}
{% templates templates = path:'/examples/dynamically_included' sort_by: 'name' sort_direction:'desc' %}
{{ templates | join: '
' }}

size filter

Returns the length of the input string or list.

size

Examples

Use the size filter to get the size of a string or a list

Using the size filter

Copy

When used on null input

{{null | size}}

When used on a string

{{"string" | size}}

When used on a list

{{"item1,item2,item3" | split:"," | size}}

When used on anything else

{{request.date | size}}

uniq filter

Remove all duplicate objects in the input list. If property is specified, objects are considered duplicate if their property value is the same.

uniq: String propertyBoolean ignorecase

Examples

Use the uniq filter to remove duplicate items from a list.

Removing duplicates from a list

Copy
{{'bookkeeper' | split: '' | uniq}}
{{'A B c d a b c' | split: ' ' | uniq}}
{{'A B c d a b c' | split: ' ' | uniq: null, true}}

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 %}

Use the list methods and filters to create and manage lists of data in your templates

Getting and manipulating entity lists

Copy
{% 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 %}

Sort the full list randomly

{% set houses = houses | shuffle %}

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 %}

{{list.Key | default: "Unknown"}} Rooms ({{list.Value | size }} houses)

{% endfor %}

Mapping and Compact

{% var mapped_by_rooms = grouped_by_rooms | map: "Value" %} {% for list in mapped_by_rooms %}

{{list[0].rooms | default: "Unknown"}} Rooms

  • {{list | map: "description" | compact | join: "
  • " }}
{% endfor %}

first filter

Returns the first item in the input list

first

Examples

Use the first and last filter to get a specific item in a list. In some cases, you can use square bracket notation to get an item at a specific index.

Getting a specific item from a list

Copy
{% var input = 'a,b,c,d' | split:',' %}

first

{{input | first}}

last

{{input | last}}

square bracket

{{input[2]}}
[{{input[5]}}]
{{input[-1]}}

last filter

Returns the last item in the input list

last

Examples

Use the first and last filter to get a specific item in a list. In some cases, you can use square bracket notation to get an item at a specific index.

Getting a specific item from a list

Copy
{% var input = 'a,b,c,d' | split:',' %}

first

{{input | first}}

last

{{input | last}}

square bracket

{{input[2]}}
[{{input[5]}}]
{{input[-1]}}

reverse filter

Reverses the input string or list.

reverse

Examples

Use the reverse filter to reverse either a string or a list

Using the reverse filter

Copy

When used on null input

{{null | reverse | object_type}}

When used on a string

{{"string" | reverse}}

When used on a list

{{"item1,item2,item3" | split:"," | reverse | join:" "}}

sort_natural filter

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

sort_natural: String property

Examples

Use the sort, sort_natural, and shuffle filters to sort lists of objects. For consistency and readability, the sort filter should be preferred to the sort_natural filter.

Sorting lists

Copy
{% var stringinputs = 'JucLPXeHBgaZokTRsymNqwFViD' | split: '' %} {% var numberinputs = (1..10) | shuffle %} {{ numberinputs | json_encode }}

Sort strings

{{ stringinputs | sort }}
{{ stringinputs | sort: null, true }}
{{ stringinputs | sort_natural }}

Sort numbers

{{ numberinputs | sort | join }}

Sort objects

{% var sorted = houses | sort: 'number_of_rooms' %}
{% var sorted = houses | sort: 'name', true %}

Sort randomly

{{ stringinputs | shuffle | join: '' }}
{{ numberinputs | sort: 'random' | join }}

sort filter

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 identicial to using the shuffle filter.

sort: String propertyBoolean ignorecase

Examples

Use the sort, sort_natural, and shuffle filters to sort lists of objects. For consistency and readability, the sort filter should be preferred to the sort_natural filter.

Sorting lists

Copy
{% var stringinputs = 'JucLPXeHBgaZokTRsymNqwFViD' | split: '' %} {% var numberinputs = (1..10) | shuffle %} {{ numberinputs | json_encode }}

Sort strings

{{ stringinputs | sort }}
{{ stringinputs | sort: null, true }}
{{ stringinputs | sort_natural }}

Sort numbers

{{ numberinputs | sort | join }}

Sort objects

{% var sorted = houses | sort: 'number_of_rooms' %}
{% var sorted = houses | sort: 'name', true %}

Sort randomly

{{ stringinputs | shuffle | join: '' }}
{{ numberinputs | sort: 'random' | join }}

Use the list methods and filters to create and manage lists of data in your templates

Getting and manipulating entity lists

Copy
{% 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 %}

Sort the full list randomly

{% set houses = houses | shuffle %}

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 %}

{{list.Key | default: "Unknown"}} Rooms ({{list.Value | size }} houses)

{% endfor %}

Mapping and Compact

{% var mapped_by_rooms = grouped_by_rooms | map: "Value" %} {% for list in mapped_by_rooms %}

{{list[0].rooms | default: "Unknown"}} Rooms

  • {{list | map: "description" | compact | join: "
  • " }}
{% endfor %}

split filter

Split a string into a list of substrings separated by the given separator

split: String separator

Examples

Use the split filter to convert a string into a list of strings separated by the given separator

Using the split filter

Copy
{{'The quick brown fox jumps over the lazy dog.' | split:" " | json_encode}}

Split on multiple characters

{{'She sells sea shells on the sea shore.' | split:"sea" | json_encode}}

Does not include empty strings in the result

{{"110100101" | split:'1' | json_encode}}

Use an empty pattern to split the string into individual characters

{{"abcdef" | split:'' | json_encode}}

map filter

Return a new list with the given property from every object in the input list.

map: String property

Examples

Use the map filter to map blog posts to their linked title. The map filter could just as easily be used for any other property as well.

Map a list of blog posts to their linked titles

Copy
{% blog_posts posts = limit: 10 sort_by 'post_date' sort_direction:'desc' %} {{ posts | map: 'linked_title' | join: '
' }}

Use the list methods and filters to create and manage lists of data in your templates

Getting and manipulating entity lists

Copy
{% 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 %}

Sort the full list randomly

{% set houses = houses | shuffle %}

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 %}

{{list.Key | default: "Unknown"}} Rooms ({{list.Value | size }} houses)

{% endfor %}

Mapping and Compact

{% var mapped_by_rooms = grouped_by_rooms | map: "Value" %} {% for list in mapped_by_rooms %}

{{list[0].rooms | default: "Unknown"}} Rooms

  • {{list | map: "description" | compact | join: "
  • " }}
{% endfor %}

group_by filter

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.

group_by: String property

Examples

Use the group_by filter to group objects by a specific property. For example, you can group a list of blog posts by blog.

Group blog posts by blog

Copy
{% 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 %}

{{ group.Key.title }}: {{ group.Value | size }}

{% endfor %}

Use the list methods and filters to create and manage lists of data in your templates

Getting and manipulating entity lists

Copy
{% 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 %}

Sort the full list randomly

{% set houses = houses | shuffle %}

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 %}

{{list.Key | default: "Unknown"}} Rooms ({{list.Value | size }} houses)

{% endfor %}

Mapping and Compact

{% var mapped_by_rooms = grouped_by_rooms | map: "Value" %} {% for list in mapped_by_rooms %}

{{list[0].rooms | default: "Unknown"}} Rooms

  • {{list | map: "description" | compact | join: "
  • " }}
{% endfor %}

Security Filters

decrypt_aes filter

Returns the unencrypted value of the input string using a shared secret and optional salt. If no salt is provided, a default salt value is used.

decrypt_aes: String secretString salt

Examples

Use the encrypt_aes and decrypt_aes filters to encrypt and decrypt strings using the aes alrorithm.

Encrypt and decrypt strings with aes

Copy
{% var secret = "my secret string" %} {% var salt = "my salt" %}

encrypt_aes

{% var securetext = "I want this to be reasonably secure" | encrypt_aes: secret, salt %} {{securetext}}

decrypt_aes

{{securetext | decrypt_aes: secret, salt }}

encrypt_aes filter

Returns the encrypted value of the input string using a shared secret and optional salt. If no salt is provided, a default salt value is used.

encrypt_aes: String secretString salt

Examples

Use the encrypt_aes and decrypt_aes filters to encrypt and decrypt strings using the aes alrorithm.

Encrypt and decrypt strings with aes

Copy
{% var secret = "my secret string" %} {% var salt = "my salt" %}

encrypt_aes

{% var securetext = "I want this to be reasonably secure" | encrypt_aes: secret, salt %} {{securetext}}

decrypt_aes

{{securetext | decrypt_aes: secret, salt }}

base64_url_safe_encode filter

Encodes a string to a URL-safe base64 format. The difference between the base64 and URL-safe base64 formats is that the URL-safe format uses - and _ in place of + and /, which can cause problems when used in a URL.

base64_url_safe_encode

Examples

Use the base64_encode, base64_decode, base64_url_safe_encode, and base64_url_safe_decode filters to encode and decode strings to and from a base64 format.

Encoding and decoding from base64

Copy

base64_encode

{{ '>>> do you want to stop?' | base64_encode }}

base64_decode

{{ 'Pj4+IGRvIHlvdSB3YW50IHRvIHN0b3A/' | base64_decode }}

base64_url_safe_encode

{{ '>>> do you want to stop?' | base64_url_safe_encode }}

base64_url_safe_decode

{{ 'Pj4-IGRvIHlvdSB3YW50IHRvIHN0b3A_' | base64_url_safe_decode }}

base64_url_safe_decode filter

Decodes a string from a URL-safe base64 format. The difference between the base64 and URL-safe base64 formats is that the URL-safe format uses - and _ in place of + and /, which can cause problems when used in a URL.

base64_url_safe_decode

Examples

Use the base64_encode, base64_decode, base64_url_safe_encode, and base64_url_safe_decode filters to encode and decode strings to and from a base64 format.

Encoding and decoding from base64

Copy

base64_encode

{{ '>>> do you want to stop?' | base64_encode }}

base64_decode

{{ 'Pj4+IGRvIHlvdSB3YW50IHRvIHN0b3A/' | base64_decode }}

base64_url_safe_encode

{{ '>>> do you want to stop?' | base64_url_safe_encode }}

base64_url_safe_decode

{{ 'Pj4-IGRvIHlvdSB3YW50IHRvIHN0b3A_' | base64_url_safe_decode }}

base64_encode filter

Encodes a string to Base64 format

base64_encode

Examples

Use the base64_encode, base64_decode, base64_url_safe_encode, and base64_url_safe_decode filters to encode and decode strings to and from a base64 format.

Encoding and decoding from base64

Copy

base64_encode

{{ '>>> do you want to stop?' | base64_encode }}

base64_decode

{{ 'Pj4+IGRvIHlvdSB3YW50IHRvIHN0b3A/' | base64_decode }}

base64_url_safe_encode

{{ '>>> do you want to stop?' | base64_url_safe_encode }}

base64_url_safe_decode

{{ 'Pj4-IGRvIHlvdSB3YW50IHRvIHN0b3A_' | base64_url_safe_decode }}

base64_decode filter

Decodes a string from Base64 format

base64_decode

Examples

Use the base64_encode, base64_decode, base64_url_safe_encode, and base64_url_safe_decode filters to encode and decode strings to and from a base64 format.

Encoding and decoding from base64

Copy

base64_encode

{{ '>>> do you want to stop?' | base64_encode }}

base64_decode

{{ 'Pj4+IGRvIHlvdSB3YW50IHRvIHN0b3A/' | base64_decode }}

base64_url_safe_encode

{{ '>>> do you want to stop?' | base64_url_safe_encode }}

base64_url_safe_decode

{{ 'Pj4-IGRvIHlvdSB3YW50IHRvIHN0b3A_' | base64_url_safe_decode }}

Miscellaneous Filters

default filter

If the input is null, an empty string, or invalid (object.is_valid == false), return the default value. Otherwise returns the input. Note that if the input is the boolean value false, this will return false.

default: object default

Examples

Output a default value if the input string is empty

Default String

Copy
{% var greeting = "" %} {{ greeting | default: "hello" }} world {% set greeting = "goodbye" %} {{ greeting | default: "hello" }} world

Provide a default value for a numeric query parameter

Default Numeric Query Parameter

Copy
{% var page = request.query_params['page'] | to_int | default: 1 %}

Format filter

Returns the input formatted as a string using the provided format string. There are three types of objects that can be formatted, and each type uses its own format strings.

Numbers

Require a valid standard or custom .NET numeric format string. This is identical to using the format_number filter on a number.

Dates

Require a valid standard or custom .NET date format.

Time Diffs

Require a valid standard or custom.NET TimeSpan format.

If the input object is a string that can be converted to a date, it will be converted to a date before formatting. Otherwise if the input object is a string that can be converted to a number, it will be converted to a number before formatting.

format: String format

Examples

Format numbers using standard or custom .NET numeric format strings.

Format Numbers

Copy
{{5.9 | format_number: "F4"}} {{5.9 | format_number: "F0"}} {{5.9 | floor | format_number: "D"}} {{-12445.6789 | format_number: "N"}} {{11 | format_number: "D8"}} {{1234567890 | format_number: "(###) ###-####"}}

Format dates using standard or custom .NET date formats.

Format Dates

Copy
{{request.date | format: "d"}}
{{request.date | format: "D"}}
{{request.date | format: "o"}}
{{request.date | format: "MMMM dd, yyyy"}}

Format time diffs using standard or custom.NET TimeSpan formats.

Format Time Diffs

Copy
{% var diff = request.date | add_days: 3 | time_diff: request.date %}
{{ diff | format: "g" }}
{{ diff | format: "dd 'days'" }}

Inspect filter

Returns a json-like representation of the current object up to depth layers deep (max 10). Will not load new information from the server unless forceLoad is set to true. Useful during template development and debugging, but do not rely on the result of the inspect tag for your live site.

inspect: Number depthBoolean force_load

Examples

Use the inspect filter to learn or troubleshoot the properties of an unknown field or object.

Inspect an uknown field

Copy
{{entity.what_is_this | inspect: 5}} (inspect up to 5 layers deep, but do not load any new data from the server) {{variable | inspect: 3, true}} (inspect up to 3 layers deep, and load any necessary data from the server)

object_type filter

Returns a string identifying the type of the input object. If generic_object_check is true, will return "object" for most objects. If generic_object_check is false or unspecified, will return the value of {{ object.object_type }} for objects with an object_type property.

object_type: Boolean generic_object_check

Examples

Use the object_type filter to get the type of an unknown property or variable.

Output the type of an unknown variable

Copy
{% blog_post post = "post" %} {{ post | object_type }} {{ post | object_type: true }}

rand filter

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

rand: Integer lengthBoolean allow_repeatsBoolean prevent_cache

Examples

Use the random filter to get a random number between 1 and 10. This will result in the page being unable to cached for faster future page loads.

Get a random number between 1 and 10

Copy
{{ 10 | rand }}

Use the random filter to get a random number between 0 and 10, and allow the results to be cached for faster future page loads.

Get a random number between 0 and 10

Copy
{{ 11 | rand: 1, true, false | minus: 1 }}

Use the random filter to get four random numbers between 1 and 10. The same number may be included multiple times in the resulting list. This will result in the page being unable to cached for faster future page loads.

Get 4 random numbers between 1 and 10

Copy
{{ 10 | rand: 4 }}

Use the random filter to get four random numbers between 1 and 10, with no repeated numbers. This will result in the page being unable to cached for faster future page loads.

Get 4 unique random numbers between 1 and 10

Copy
{{ 10 | rand: 4, false }}

Use the rand filter to get a random character from a string

Get a random character from a string

Copy
{{ "input" | rand }}

Use the rand filter to generate a random string 10 characters long, composed of letters and digits. The resulting string may include repeated characters.

Generate a random alphanumeric string 10 characters long

Copy
{{ "abcdefghijklmnopqrstuvwxyz0123456789" | rand: 10 }}

Use the random filter to get a random blog post from a list of blog posts.

Get a random blog post from a list of blog posts

Copy
{% blog_posts posts = start:1 limit:10 %} {% var randompost = posts | rand %}

Use the rand filter to get 3 random blog posts from a list of blog posts. Do not allow duplicates.

Get 3 random blog posts from a list of blog posts

Copy
{% blog_posts posts = start:1 limit:10 %} {% var randomposts = posts | rand:3, false %}

to_boolean filter

Converts the input to true or false if possible. If not returns null.

to_boolean

Examples

Convert a query parameter to a boolean value with a default value of true.

Convert to boolean

Copy
{% var show_buttons = request.query_params['show_btns'] | to_boolean | default:true %}

to_number filter

Converts the input to a number.

to_number

Examples

Convert a query parameter to a number with a default value.

Convert to number

Copy
{% var average = request.query_params['average'] | default: 2.5 | to_number %}

to_int filter

Converts the input to an integer.

to_int

Examples

Convert a query parameter to an integer value with a default value.

Convert to integer

Copy
{% var limit = request.query_params['limit'] | default: 20 | to_int %}