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

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
hello world
goodbye 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 %}

Related

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

format: String format

Examples

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

How to use the format filter to format numbers

Copy

Format a number with 2 decimal places and group separators

{{ -1234.5678 | format_number: 'N2' }}
-1,234.57
Uses .NET-style numeric format strings (N2 = number with 2 decimal places and group separator).

Format a number with 4 decimal places and no group separators

{{55555.9 | format_number: "F4"}}
55555.9000
Uses .NET-style numeric format strings (F4 = number with 4 decimal places).

Format a number with no decimal places

{{5.9 | format_number: "F0"}}
6
Uses .NET-style numeric format strings (F0 = number with no decimal places). The number is rounded as necessary to fit the format string. If you want to round down to the nearest integer, you can use the floor filter instead of the format_number filter.

Format a percent

{{ 0.333333 | format: 'P1' }}
33.3%
Uses .NET-style percentage format strings (P1 = percentage with 1 decimal place).

Format an integer with leading zeros

{{ 12345 | format: 'D8' }}
00012345
Uses .NET-style decimal format strings (D8 = decimal with 8 digits). The decimal format string is only valid for integers.

Format a number with a custom numeric format string

{{ 1234567890 | format: '(###) ###-####' }}
{{ 42 | format: 'My Number = #' }}
(123) 456-7890
My Number = 42
Outputs two numbers formatted with different custom .NET-style format strings.

Format dates using standard or custom .NET date formats.

How to use the format filter to format dates

Copy
{% var sep9 = '2009-09-09 14:00:00Z' | date | to_timezone: 'America/New_York' %}

Format a date as a short date string

{{sep9 | format: "d"}}
9/9/2009
Formats a date as a short date string (d = short date).

Format a date as a short date string with the time

{{sep9 | format: "g"}}
9/9/2009 10:00 AM
Formats a date as a short date string with the time (g = short date with time).

Format a date as a long date string

{{sep9 | format: "D"}}
Sunday, September 9, 2009
Formats a date as a long date string (D = long date).

Format a date as a long date string with the time

{{sep9 | format: "f"}}
Sunday, September 9, 2009 10:00 AM
Formats a date as a long date string with the time (f = long date with time).

Format a date according to the ISO 8601 standard

{{sep9 | format: "o"}}
9/9/2009 2:00:00 PM
Formats a date according to the ISO 8601 standard (o = round trip format with offset).

Format a date as a sortable date string

{{sep9 | format: "u"}}
9/9/2009 2:00:00 PM
Formats a date as a sortable date string (u = universal sortable date in UTC timezone).

Format a date to a long date string using a custom date format string

{{sep9 | format: "MMMM dd, yyyy 'at' HH:mm:ss"}}
September 09, 2009 at 10:00:00
Formats a date using a custom .NET date format string.

Format a date to a short date string using a custom date format string

{{sep9 | format: "hh:mm tt 'on' MM-dd-yy"}}
10:00 AM on 09-09-09
Formats a date using a custom .NET date format string.

You can also use the date filter to format a date

{{sep9 | date: "hh:mm tt 'on' MM-dd-yy"}}
10:00 AM on 09-09-09
The date and format filters use the same format strings for dates, but the date filter can only be used to format dates while the format filter can also be used to format numbers and time diffs.

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

How to use the format filter to format time diffs

Copy
{% var startdate = '2009-09-09 14:00:00Z' | date | to_timezone: 'America/New_York' %}
{% var enddate = '2009-09-10 17:32:00Z' | date | to_timezone: 'America/New_York' %}
{% var diff = startdate | time_diff: enddate %}

Format a time diff as a constant time span string

{{ diff | format: "c" }}
-1.03:32:00
Formats a time diff as a constant time span string (c = constant time span).

Format a time diff as a compact time span string

{{ diff | format: "g" }}
-1:3:32:00

Format a time diff using a custom .NET TimeSpan format string

{% if diff.total_seconds < 0 %}-{% endif %}{{ diff | format: "d' days, 'h' hours, and 'm' minutes'" }}
-1 days, 3 hours, and 32 minutes
Formats a time diff using a custom .NET TimeSpan format string. Since custom .NET TimeSpan format strings do not have a way to output the minus sign for negative time spans, you have to check for negative time spans separately.

Related

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 unknown field

Copy

Inspect up to 5 layers deep, but do not load any new data from the server

{{entity.what_is_this | inspect: 5}}

Inspect up to 3 layers deep, and load any necessary data from the server

{{variable | inspect: 3, true}}

Related

object_type filter

Returns a string identifying the type of the input object. If generic_object_check is true, will return &quot;object&quot; 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

The most common object_type values are: null, object, string, boolean, date, number, list, other specific object types (article, blog_post, etc...)

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

Related

object

May be any object, including simple, complex and list objects. In some cases may even include symbols and null.

{% set_content_type %}

Sets the Content-Type header for the HTTP response.

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

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.

Examples

Use the rand filter to pick one or more random items from a list, get random numbers, or build random strings. Assign results to a variable so the same random choice is used everywhere on the page; use prevent_cache: false when you want the page response to be cacheable.

Getting random items with the rand filter

Copy

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.

Related

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

Related

boolean

True or False

to_int filter

Converts the input to an integer.

to_int

If the input is null, returns 0. If the input is non-null and cannot be convert to an integer, returns null.

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

Related

DEPRECATED for_json filter

This filter has been deprecated. You should 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}} }
{"something": "with \"value\""}
{"something": }

The for_json filter works for input with valid values

{"something": {{'with "value"' | for_json}} }
{"something": "with \"value\""}

The for_json filter does not produce output if the input is null

{"something": {{null | for_json}} }
{"something": }

You can get away with the for_json filter by manually handling null/invalid values

{"something": {% if variable is_valid %}{{variable | for_json}}{% else %}null{% endif %} }

The entire for_json filter is deprecated because the json_encode filter handles this and other uses cases more robustly

{"something": {{variable | json_encode }} }

Related

{% for %}

Iterates through every item in a list. Executes and outputs a block of code to the template for each item in the list.

to_number filter

Converts the input to a number.

to_number

If the input is null, returns 0. If the input is non-null and cannot be convert to an integer, returns null.

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

Related

number

Can be any number, including integers, decimals, or the value 0. Any value - including 0 - evaluates as true when used alone in a conditional.

to_timezone filter

Converts a date to the specified timezone.

to_timezone: String timezone

Related

{{ timezone }}

{% set_timezone %}

Sets the default timezone to use when rendering dates and times on the page that do not already have a separate timezone configured.

Number Filters

abs filter

Returns the absolute value of a number.

abs

Will attempt to convert the input to a number before calculating the absolute value, and will return 0 if it is unable to convert the input to a number.

Examples

Demonstrates how to calculate the absolute value of a number.

Calculate the absolute value of a number

Copy
{{-2 | abs}}
-2
{{"-2" | abs}}
-2
{{3.159 | abs}}
3.159
{{null | abs}}
0
{{"not a number" | abs}}
0

Related

at_least filter

Limits the input to a minimum value.

at_least: Number minimum

Converts both the input and the minimum values to numbers if they are not already numbers. If the input and minimum values cannot both be converted to numbers, return the unaltered input instead.

Examples

Use the at_least and at_most filters to limit a number to minimum and maximum values.

Using the at_least and at_most filters

Copy

at_least

{{-1 | at_least:5}}
5
{{5.255 | at_least:-1.112}}
5.255

at_most

{{-1 | at_most:5}}
-1
{{5.255 | at_most:-1.112}}
-1.112

with non-number inputs and parameters

{{"-1" | at_least:"5" | json_encode}}
5
{{"5" | at_most:"-1.345" | json_encode}}
-1.345
{{null | at_least:"5" | object_type}}
null
{{"string" | at_most:5}}
string
{{"5" | at_least:"string" | json_encode}}
"5"

Related

at_most filter

Limits the input to a maximum value.

at_most: Number maximum

Converts both the input and the maximum values to numbers if they are not already numbers. If the input and maximum values cannot both be converted to numbers, return the unaltered input instead.

Examples

Use the at_least and at_most filters to limit a number to minimum and maximum values.

Using the at_least and at_most filters

Copy

at_least

{{-1 | at_least:5}}
5
{{5.255 | at_least:-1.112}}
5.255

at_most

{{-1 | at_most:5}}
-1
{{5.255 | at_most:-1.112}}
-1.112

with non-number inputs and parameters

{{"-1" | at_least:"5" | json_encode}}
5
{{"5" | at_most:"-1.345" | json_encode}}
-1.345
{{null | at_least:"5" | object_type}}
null
{{"string" | at_most:5}}
string
{{"5" | at_least:"string" | json_encode}}
"5"

Related

ceil filter

Returns the next integer value greater than or equal to the input.

ceil

Attempts to converts the input to a number if it is not already a number. Returns null if it is unable to convert the input to a number.

Examples

Use the ceil, floor, and round filters to round numbers up and down.

Using filters to round numbers up and down

Copy

ceil

{{3.2 | ceil}}
4
{{"-3.159" | ceil}}
-3

floor

{{5.9 | floor}}
5
{{"-3.159" | floor}}
-4

round

{{9.82 | round}}
10
{{-9.825 | round: 2}}
-9.82
{{-9.835 | round: 2}}
-9.84

Non-numeric input

{{null | ceil | object_type}}
null
{{"string" | round | object_type}}
null

Related

currency filter

Converts the input into a formatted currency as specified by language_tag.

currency: String language_tag

Attempts to convert the input to a number, and if it cannot be converted to a number, the currency filter will return the input as a string instead. If the input is null, returns null. Passing an invalid language_tag results in undefined behavior - likely resulting in a liquid error.

Examples

Use the currency filter to format a tag as currency, including the leading or trailing currency identifier.

Format a number as currency

Copy

en-US (default)

{{12345.6789 | currency}}
$12,345.68
{{12345 | currency: 'en-US'}}
$12,345.00

de

{{input | currency: 'de-DE'}}
12.345,68 €

en-GB

{{input | currency: 'en-GB'}}
£12,345.68

es-VE

{{input | currency: 'es-VE'}}
Bs.S12.345,68

zh-CN

{{input | currency: 'zh-CN'}}
¥12,345.68

Related

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}}
4
{{13.3 | divided_by:1.4}}
9.5

Related

floor filter

Returns the next integer value less than or equal to the input value.

floor

Attempts to converts the input to a number if it is not already a number. Returns null if it is unable to convert the input to a number.

Examples

Use the ceil, floor, and round filters to round numbers up and down.

Using filters to round numbers up and down

Copy

ceil

{{3.2 | ceil}}
4
{{"-3.159" | ceil}}
-3

floor

{{5.9 | floor}}
5
{{"-3.159" | floor}}
-4

round

{{9.82 | round}}
10
{{-9.825 | round: 2}}
-9.82
{{-9.835 | round: 2}}
-9.84

Non-numeric input

{{null | ceil | object_type}}
null
{{"string" | round | object_type}}
null

Related

format_number filter

Returns the input formatted as a string using the provided format string. The format string must be a valid standard or custom .NET numeric format string.

format_number: String format

Returns null if the input cannot be converted to a number.

Examples

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

How to use the format filter to format numbers

Copy

Format a number with 2 decimal places and group separators

{{ -1234.5678 | format_number: 'N2' }}
-1,234.57
Uses .NET-style numeric format strings (N2 = number with 2 decimal places and group separator).

Format a number with 4 decimal places and no group separators

{{55555.9 | format_number: "F4"}}
55555.9000
Uses .NET-style numeric format strings (F4 = number with 4 decimal places).

Format a number with no decimal places

{{5.9 | format_number: "F0"}}
6
Uses .NET-style numeric format strings (F0 = number with no decimal places). The number is rounded as necessary to fit the format string. If you want to round down to the nearest integer, you can use the floor filter instead of the format_number filter.

Format a percent

{{ 0.333333 | format: 'P1' }}
33.3%
Uses .NET-style percentage format strings (P1 = percentage with 1 decimal place).

Format an integer with leading zeros

{{ 12345 | format: 'D8' }}
00012345
Uses .NET-style decimal format strings (D8 = decimal with 8 digits). The decimal format string is only valid for integers.

Format a number with a custom numeric format string

{{ 1234567890 | format: '(###) ###-####' }}
{{ 42 | format: 'My Number = #' }}
(123) 456-7890
My Number = 42
Outputs two numbers formatted with different custom .NET-style format strings.

Related

number

Can be any number, including integers, decimals, or the value 0. Any value - including 0 - evaluates as true when used alone in a conditional.

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}}
4
{{13.3 | minus:14.4}}
-1.1

Related

modulo filter

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

modulo: Number operand

If the input is negative, the result will also be negative. Otherwise the result will be positive.

Examples

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

Using the modulo filter

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

Related

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

The plus filter may behave differently when used with string input. When used with a string input it may append text to the current value, although that behavior is deprecated and should be replaced by the append filter for optimal forward-compatibility.

Examples

Demonstrates how to add some numbers together.

Add some numbers together

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

Add two integers with plus

3+5 = {{3 | plus: 5}}
3+5 = 8
Uses the plus filter to add two integer values.

Add decimal numbers with plus

-4.2+2.1 = {{-4.2 | plus: 2.1}}
-4.2+2.1 = -2.1
Shows that the plus filter also works with decimal numbers.

Related

round filter

Rounds the input to the specified number of decimal places.

round: Integer places

Attempts to converts the input to a number if it is not already a number. Returns null if it is unable to convert the input to a number, or if places is specified but cannot be converted to an integer. If the input is exactly halfway between the smaller and larger number, the round filter will attempt to round toward the nearest even number in the last decimal place (eg: 4.35 rounded to one decimal place would be 4.4)

Examples

Use the ceil, floor, and round filters to round numbers up and down.

Using filters to round numbers up and down

Copy

ceil

{{3.2 | ceil}}
4
{{"-3.159" | ceil}}
-3

floor

{{5.9 | floor}}
5
{{"-3.159" | floor}}
-4

round

{{9.82 | round}}
10
{{-9.825 | round: 2}}
-9.82
{{-9.835 | round: 2}}
-9.84

Non-numeric input

{{null | ceil | object_type}}
null
{{"string" | round | object_type}}
null

Related

times filter

Multiply the input by the operand.

times: Number 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.

Examples

Use the times filter to multiply a number by another number

Multiply numbers

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

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}}
["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"]

Related

{{ time }}

Represents a specific instant in a specific timezone.

Go to to_int filter filter documentation

Go to to_number filter filter documentation

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

Related

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}}
A Freight Train Running Through The

Related

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: ""}}
a-long-classname
a_long_classname
alongclassname

Related

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}}
a freight train running through the

Related

escape filter

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

escape

Examples

Escape HTML characters for safe output inside other HTML. Use escape for full escaping; use escape_once when content may already be partially escaped to avoid double-encoding.

Escape HTML (escape and escape_once)

Copy

escape

<p title="{{"<p>A string with HTML & other characters</p>" | escape}}">...
<p title="&lt;p&gt;A string with HTML &amp; other characters&lt;/p&gt;">...
Escapes all HTML and special characters.

escape_once

<p title="{{"&lt;p&gt;A string with some characters encoded & others not encoded&lt;/p>" | escape_once}}">...
<p title="&lt;p&gt;A string with some characters encoded &amp; others not encoded&lt;/p&gt;">...
Escapes only characters that are not already escaped, avoiding double-encoding.

Related

escape_once filter

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

escape_once

Related

Go to DEPRECATED for_json filter filter documentation

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

Related

html_decode filter

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

html_decode

Examples

Decode any encoded HTML entities inside a string.

Decode HTML entities in a string

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

Related

{{ html }}

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: &lt; becomes &lt;). 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
<p title="{{"<p>A string with HTML & other characters</p>" | html_encode}}">...
<p title="&lt;p&gt;A string with HTML &amp; other characters&lt;/p&gt;">...

Related

{{ html }}

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

Use the index and last_index filters on a string to find the position of a substring. index searches forward; last_index searches backward.

Finding substring position with index and last_index

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

Related

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}}
"liquid" filter

Related

json_encode filter

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

json_encode

Null values output the string &quot;null&quot;. Dates are output using the ISO 8601 standard. Booleans are output as &quot;true&quot; or &quot;false&quot;. Numbers are output as numbers. Strings are output as json encoded strings with quote marks properly escaped.

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 -}}
}
{
"null": null,
"date": "2009-06-15T13:45:30.0000000Z",
"true": true,
"3": 3,
"-4.2": -4.2,
"string": "Liquid is \"cool\""
}

Related

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

Related

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}}]
[The quick brown fox jumps over the lazy dog. ]
[{{sentence_with_extra_whitespace | rstrip}}]
[ The quick brown fox jumps over the lazy dog.]
[{{sentence_with_extra_whitespace | strip}}]
[The quick brown fox jumps over the lazy dog.]

Related

newline_to_br filter

Add &lt;br /&gt; tags in front of all newlines in the current string

newline_to_br

Examples

Demonstrates how to add <br /> in front of all newlines in a string.

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

Copy
{%- capture input -%}
ABC
DEF
GHI
{%- endcapture -%}
{{-input | newline_to_br}}
ABC<br />
DEF<br />
GHI

Related

Go to plus filter filter documentation

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

Related

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'}}
ly for les development
{{input | remove_first:'app'}}
ly for apples app development
{{input | remove_first:'app', 2}}
ly for les app development

The remove and remove_first filters are case-sensitive

{{ input | remove:'App' }}
apply for apples app development

Related

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'}}
ly for les development
{{input | remove_first:'app'}}
ly for apples app development
{{input | remove_first:'app', 2}}
ly for les app development

The remove and remove_first filters are case-sensitive

{{ input | remove:'App' }}
apply for apples app development

Related

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'}}
moply for moples mop development
{{input | replace_first:'app', 'mop'}}
moply for apples app development
{{input | replace_first:'app', 'mop', 2}}
moply for moples app development

The replace and replace_first filters are case-sensitive

{{ input | replace:'App', 'Mop'}}
apply for apples app development

Related

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'}}
moply for moples mop development
{{input | replace_first:'app', 'mop'}}
moply for apples app development
{{input | replace_first:'app', 'mop', 2}}
moply for moples app development

The replace and replace_first filters are case-sensitive

{{ input | replace:'App', 'Mop'}}
apply for apples app development

Related

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'}}
The quick brown dragon jumps over the lazy dragon.
{{input | replace_regex_first:'/dog/i', 'dragon'}}
The quick brown dragon jumps over the lazy dog.
{{input | replace_regex_first:'(quick|brown|lazy)', 'adjective:$1', 2}}
The adjective:quick adjective:brown dog jumps over the lazy dog.

Related

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'}}
The quick brown dragon jumps over the lazy dragon.
{{input | replace_regex_first:'/dog/i', 'dragon'}}
The quick brown dragon jumps over the lazy dog.
{{input | replace_regex_first:'(quick|brown|lazy)', 'adjective:$1', 2}}
The adjective:quick adjective:brown dog jumps over the lazy dog.

Related

reverse filter

Reverses the input string or list.

reverse

When used with a string as input, the result is a string. Otherwise the result is a list.

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

When used on a string

{{"string" | reverse}}
gnirts

When used on a list

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

Related

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}}]
[The quick brown fox jumps over the lazy dog. ]
[{{sentence_with_extra_whitespace | rstrip}}]
[ The quick brown fox jumps over the lazy dog.]
[{{sentence_with_extra_whitespace | strip}}]
[The quick brown fox jumps over the lazy dog.]

Related

size filter

Returns the length of the input string or list.

size

If the input is not a string or list returns 0.

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

Related

slice filter

Return a part of the current string or list.

slice: Integer startInteger length

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.

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

Related

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}}
["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"]

Related

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}}]
[The quick brown fox jumps over the lazy dog. ]
[{{sentence_with_extra_whitespace | rstrip}}]
[ The quick brown fox jumps over the lazy dog.]
[{{sentence_with_extra_whitespace | strip}}]
[The quick brown fox jumps over the lazy dog.]

Related

strip_html filter

Removes all HTML tags from a string

strip_html

This filter uses simple pattern matching to remove HTML tags. If the input is poorly formatted or contains unusual character sequences - particularly involving the &#39;&lt;&#39; and &#39;&gt;&#39; characters - this could result in unexpected behavior.

Examples

Demonstrates how to strip HTML from an input string.

Strip HTML from an input string

Copy
{{'<p>The quick brown fox jumps over the lazy dog.</p>' | strip_html}}
The quick brown fox jumps over the lazy dog.
{%- capture input -%}
<script>... this will strip script blocks ...</script>
<style>... this will also strip style blocks ...</style>
<!-- and this will strip HTML comments -->
<p title="this will strip the open and close tags but leave the content intact">The quick brown fox jumps over the lazy dog.</p>
<br />
<img src="..." alt="note that this will also strip images" />
{%- endcapture -%}
{{-input | strip_html | strip}}
The quick brown fox jumps over the lazy dog.

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}}
//script outside of a script tag
if (a b)
doSomethingElse();
//endscript

Could result in unexpected behavior with poorly formatted input

{%- capture input -%}
<p>The following invalid markup contains an unescaped &gt; character in an HTML attribute:
<input type="button" onclick="if(a>b) doSomething();" value="Do Something" /></p>
{%- endcapture -%}
{{-input | strip_html | strip}}
The following invalid markup contains an unescaped &gt; character in an HTML attribute:
b) doSomething();" value="Do Something" />

Related

{{ html }}

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

Related

Go to times filter filter documentation

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}}
The quick brown fox jumps over...
{{input | truncate:33 | size}}
33
{{input | truncate:31, " (more)"}}
The quick brown fox jump (more)
{{input | truncate:33, ""}}
The quick brown fox jumps over th
{{'Shorter than 33 characters' | truncate: 33}}
Shorter than 33 characters

truncate_to_word

{{input | truncate_to_word:30}}
The quick brown fox jumps...
{{input | truncate_to_word:30 | size}}
28
{{input | truncate_to_word:30, false}}
The quick brown fox jumps over...
{{input | truncate_to_word:30, false | size}}
33

truncate_words

{{input | truncate_words:3}}
The quick brown...
{{input | truncate_words:3, " (more)"}}
The quick brown (more)
{{input | truncate_words:9}}
The quick brown fox jumps over the lazy dog.

Related

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

The truncate_to_word uses a naive algorithm for word counting that considers words as one or more letters, digits, underscores, or apostrophes. All other characters are considered non-word characters in between words. This means that a string could still be truncated in the middle of a hypenated word or a word with other non-word characters such as &quot;awe-inspiring&quot;, &quot;r&amp;r&quot;, &quot;1.25&quot;, &quot;3/4&quot;, etc.... This filter also does not strip or consolidate whitespace, or handle HTML markup any different than normal text.

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}}
The quick brown fox jumps over...
{{input | truncate:33 | size}}
33
{{input | truncate:31, " (more)"}}
The quick brown fox jump (more)
{{input | truncate:33, ""}}
The quick brown fox jumps over th
{{'Shorter than 33 characters' | truncate: 33}}
Shorter than 33 characters

truncate_to_word

{{input | truncate_to_word:30}}
The quick brown fox jumps...
{{input | truncate_to_word:30 | size}}
28
{{input | truncate_to_word:30, false}}
The quick brown fox jumps over...
{{input | truncate_to_word:30, false | size}}
33

truncate_words

{{input | truncate_words:3}}
The quick brown...
{{input | truncate_words:3, " (more)"}}
The quick brown (more)
{{input | truncate_words:9}}
The quick brown fox jumps over the lazy dog.

Related

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

The truncate_words uses a naive algorithm for word counting that considers words as one or more letters, digits, underscores, or apostrophes. All other characters are considered non-word characters in between words. This means that hyphenated words such as &quot;awe-inspiring&quot; are counted as two words, as are &quot;words&quot; with other characters between letters, such as &quot;r&amp;r&quot;, &quot;1.25&quot;, &quot;3/4&quot;, etc.... This filter also does not strip or consolidate whitespace, or handle HTML markup any different than normal text.

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}}
The quick brown fox jumps over...
{{input | truncate:33 | size}}
33
{{input | truncate:31, " (more)"}}
The quick brown fox jump (more)
{{input | truncate:33, ""}}
The quick brown fox jumps over th
{{'Shorter than 33 characters' | truncate: 33}}
Shorter than 33 characters

truncate_to_word

{{input | truncate_to_word:30}}
The quick brown fox jumps...
{{input | truncate_to_word:30 | size}}
28
{{input | truncate_to_word:30, false}}
The quick brown fox jumps over...
{{input | truncate_to_word:30, false | size}}
33

truncate_words

{{input | truncate_words:3}}
The quick brown...
{{input | truncate_words:3, " (more)"}}
The quick brown (more)
{{input | truncate_words:9}}
The quick brown fox jumps over the lazy dog.

Related

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}}
A FREIGHT TRAIN RUNNING THROUGH THE

Related

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%20filter
{{"liquid filter" | url_encode:true}}
liquid+filter

url_decode

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

Related

{% image_url %}

Resolves the URL for an image with the desired presets and other settings applied.

{{ url }}

Field containing a URL.

{% set_canonical_url %}

Sets the canonical URL for the current page, which is output by default as part of an HTML page's {{ automatic_markup }}.

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%20filter
{{"liquid filter" | url_encode:true}}
liquid+filter

url_decode

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

Related

{% image_url %}

Resolves the URL for an image with the desired presets and other settings applied.

{{ url }}

Field containing a URL.

{% set_canonical_url %}

Sets the canonical URL for the current page, which is output by default as part of an HTML page's {{ automatic_markup }}.

Date Filters

add_years filter

Return a date object operand years in the future from the input date.

add_years: Integer operand

If operand is negative, return a date that many years in the past from the input date.

Examples

Use the add_seconds, add_minutes, add_hours, add_days, add_weeks, add_months, and add_years filters to manipulate dates.

Use math to manipulate dates

Copy
{% var startdate = '2009-09-09T00:00:00Z' | to_timezone: 'UTC' %}

add_seconds

{{ startdate | add_seconds: 3 }}
9/9/2009 12:00:03 AM
{{ startdate | add_seconds: -10239 }}
9/8/2009 9:09:21 PM

add_minutes

{{ startdate | add_minutes: 3 }}
9/9/2009 12:03:00 AM
{{ startdate | add_minutes: -180 }}
9/8/2009 9:00:00 PM

add_hours

{{ startdate | add_hours: 3 }}
9/9/2009 3:00:00 AM
{{ startdate | add_hours: -32 }}
9/7/2009 4:00:00 PM

add_days

{{ startdate | add_days: 3 }}
9/12/2009 12:00:00 AM
{{ startdate | add_days: -2 }}
9/7/2009 12:00:00 AM

add_weeks

{{ startdate | add_weeks: 3 }}
9/30/2009 12:00:00 AM
{{ startdate | add_weeks: -7 }}
7/22/2009 12:00:00 AM

add_months

{{ startdate | add_months: 3 }}
12/9/2009 12:00:00 AM
{{ startdate | add_months: -10 }}
11/9/2008 12:00:00 AM

add_years

{{ startdate | add_years: 3 }}
9/9/2012 12:00:00 AM
{{ startdate | add_years: -1 }}
9/9/2008 12:00:00 AM

Related

{% add_stylesheet %}

Add a stylesheet asset to the head of the current page via a <link> tag

{% add_javascript %}

Add a script asset to the current page via a <script> tag

{% add_javascript inline %}

Outputs javascript code in an inline script

{% add_stylesheet inline %}

Outputs an inline stylesheet in a <style> tag.

add_weeks filter

Return a date object operand weeks in the future from the input date.

add_weeks: Integer operand

If operand is negative, return a date that many weeks in the past from the input date.

Examples

Use the add_seconds, add_minutes, add_hours, add_days, add_weeks, add_months, and add_years filters to manipulate dates.

Use math to manipulate dates

Copy
{% var startdate = '2009-09-09T00:00:00Z' | to_timezone: 'UTC' %}

add_seconds

{{ startdate | add_seconds: 3 }}
9/9/2009 12:00:03 AM
{{ startdate | add_seconds: -10239 }}
9/8/2009 9:09:21 PM

add_minutes

{{ startdate | add_minutes: 3 }}
9/9/2009 12:03:00 AM
{{ startdate | add_minutes: -180 }}
9/8/2009 9:00:00 PM

add_hours

{{ startdate | add_hours: 3 }}
9/9/2009 3:00:00 AM
{{ startdate | add_hours: -32 }}
9/7/2009 4:00:00 PM

add_days

{{ startdate | add_days: 3 }}
9/12/2009 12:00:00 AM
{{ startdate | add_days: -2 }}
9/7/2009 12:00:00 AM

add_weeks

{{ startdate | add_weeks: 3 }}
9/30/2009 12:00:00 AM
{{ startdate | add_weeks: -7 }}
7/22/2009 12:00:00 AM

add_months

{{ startdate | add_months: 3 }}
12/9/2009 12:00:00 AM
{{ startdate | add_months: -10 }}
11/9/2008 12:00:00 AM

add_years

{{ startdate | add_years: 3 }}
9/9/2012 12:00:00 AM
{{ startdate | add_years: -1 }}
9/9/2008 12:00:00 AM

Related

{% add_stylesheet %}

Add a stylesheet asset to the head of the current page via a <link> tag

{% add_javascript %}

Add a script asset to the current page via a <script> tag

{% add_javascript inline %}

Outputs javascript code in an inline script

{% add_stylesheet inline %}

Outputs an inline stylesheet in a <style> tag.

add_seconds filter

Return a date object operand seconds in the future from the input date.

add_seconds: Integer operand

If operand is negative, return a date that many seconds in the past from the input date.

Examples

Use the add_seconds, add_minutes, add_hours, add_days, add_weeks, add_months, and add_years filters to manipulate dates.

Use math to manipulate dates

Copy
{% var startdate = '2009-09-09T00:00:00Z' | to_timezone: 'UTC' %}

add_seconds

{{ startdate | add_seconds: 3 }}
9/9/2009 12:00:03 AM
{{ startdate | add_seconds: -10239 }}
9/8/2009 9:09:21 PM

add_minutes

{{ startdate | add_minutes: 3 }}
9/9/2009 12:03:00 AM
{{ startdate | add_minutes: -180 }}
9/8/2009 9:00:00 PM

add_hours

{{ startdate | add_hours: 3 }}
9/9/2009 3:00:00 AM
{{ startdate | add_hours: -32 }}
9/7/2009 4:00:00 PM

add_days

{{ startdate | add_days: 3 }}
9/12/2009 12:00:00 AM
{{ startdate | add_days: -2 }}
9/7/2009 12:00:00 AM

add_weeks

{{ startdate | add_weeks: 3 }}
9/30/2009 12:00:00 AM
{{ startdate | add_weeks: -7 }}
7/22/2009 12:00:00 AM

add_months

{{ startdate | add_months: 3 }}
12/9/2009 12:00:00 AM
{{ startdate | add_months: -10 }}
11/9/2008 12:00:00 AM

add_years

{{ startdate | add_years: 3 }}
9/9/2012 12:00:00 AM
{{ startdate | add_years: -1 }}
9/9/2008 12:00:00 AM

Related

{% add_stylesheet %}

Add a stylesheet asset to the head of the current page via a <link> tag

{% add_javascript %}

Add a script asset to the current page via a <script> tag

{% add_javascript inline %}

Outputs javascript code in an inline script

{% add_stylesheet inline %}

Outputs an inline stylesheet in a <style> tag.

add_months filter

Return a date object operand months in the future from the input date.

add_months: Integer operand

If operand is negative, return a date that many months in the past from the input date.

Examples

Use the add_seconds, add_minutes, add_hours, add_days, add_weeks, add_months, and add_years filters to manipulate dates.

Use math to manipulate dates

Copy
{% var startdate = '2009-09-09T00:00:00Z' | to_timezone: 'UTC' %}

add_seconds

{{ startdate | add_seconds: 3 }}
9/9/2009 12:00:03 AM
{{ startdate | add_seconds: -10239 }}
9/8/2009 9:09:21 PM

add_minutes

{{ startdate | add_minutes: 3 }}
9/9/2009 12:03:00 AM
{{ startdate | add_minutes: -180 }}
9/8/2009 9:00:00 PM

add_hours

{{ startdate | add_hours: 3 }}
9/9/2009 3:00:00 AM
{{ startdate | add_hours: -32 }}
9/7/2009 4:00:00 PM

add_days

{{ startdate | add_days: 3 }}
9/12/2009 12:00:00 AM
{{ startdate | add_days: -2 }}
9/7/2009 12:00:00 AM

add_weeks

{{ startdate | add_weeks: 3 }}
9/30/2009 12:00:00 AM
{{ startdate | add_weeks: -7 }}
7/22/2009 12:00:00 AM

add_months

{{ startdate | add_months: 3 }}
12/9/2009 12:00:00 AM
{{ startdate | add_months: -10 }}
11/9/2008 12:00:00 AM

add_years

{{ startdate | add_years: 3 }}
9/9/2012 12:00:00 AM
{{ startdate | add_years: -1 }}
9/9/2008 12:00:00 AM

Related

{% add_stylesheet %}

Add a stylesheet asset to the head of the current page via a <link> tag

{% add_javascript %}

Add a script asset to the current page via a <script> tag

{% add_javascript inline %}

Outputs javascript code in an inline script

{% add_stylesheet inline %}

Outputs an inline stylesheet in a <style> tag.

add_minutes filter

Return a date object operand minutes in the future from the input date.

add_minutes: Integer operand

If operand is negative, return a date that many minutes in the past from the input date.

Examples

Use the add_seconds, add_minutes, add_hours, add_days, add_weeks, add_months, and add_years filters to manipulate dates.

Use math to manipulate dates

Copy
{% var startdate = '2009-09-09T00:00:00Z' | to_timezone: 'UTC' %}

add_seconds

{{ startdate | add_seconds: 3 }}
9/9/2009 12:00:03 AM
{{ startdate | add_seconds: -10239 }}
9/8/2009 9:09:21 PM

add_minutes

{{ startdate | add_minutes: 3 }}
9/9/2009 12:03:00 AM
{{ startdate | add_minutes: -180 }}
9/8/2009 9:00:00 PM

add_hours

{{ startdate | add_hours: 3 }}
9/9/2009 3:00:00 AM
{{ startdate | add_hours: -32 }}
9/7/2009 4:00:00 PM

add_days

{{ startdate | add_days: 3 }}
9/12/2009 12:00:00 AM
{{ startdate | add_days: -2 }}
9/7/2009 12:00:00 AM

add_weeks

{{ startdate | add_weeks: 3 }}
9/30/2009 12:00:00 AM
{{ startdate | add_weeks: -7 }}
7/22/2009 12:00:00 AM

add_months

{{ startdate | add_months: 3 }}
12/9/2009 12:00:00 AM
{{ startdate | add_months: -10 }}
11/9/2008 12:00:00 AM

add_years

{{ startdate | add_years: 3 }}
9/9/2012 12:00:00 AM
{{ startdate | add_years: -1 }}
9/9/2008 12:00:00 AM

Related

{% add_stylesheet %}

Add a stylesheet asset to the head of the current page via a <link> tag

{% add_javascript %}

Add a script asset to the current page via a <script> tag

{% add_javascript inline %}

Outputs javascript code in an inline script

{% add_stylesheet inline %}

Outputs an inline stylesheet in a <style> tag.

add_hours filter

Return a date object operand hours in the future from the input date.

add_hours: Integer operand

If operand is negative, return a date that many hours in the past from the input date.

Examples

Use the add_seconds, add_minutes, add_hours, add_days, add_weeks, add_months, and add_years filters to manipulate dates.

Use math to manipulate dates

Copy
{% var startdate = '2009-09-09T00:00:00Z' | to_timezone: 'UTC' %}

add_seconds

{{ startdate | add_seconds: 3 }}
9/9/2009 12:00:03 AM
{{ startdate | add_seconds: -10239 }}
9/8/2009 9:09:21 PM

add_minutes

{{ startdate | add_minutes: 3 }}
9/9/2009 12:03:00 AM
{{ startdate | add_minutes: -180 }}
9/8/2009 9:00:00 PM

add_hours

{{ startdate | add_hours: 3 }}
9/9/2009 3:00:00 AM
{{ startdate | add_hours: -32 }}
9/7/2009 4:00:00 PM

add_days

{{ startdate | add_days: 3 }}
9/12/2009 12:00:00 AM
{{ startdate | add_days: -2 }}
9/7/2009 12:00:00 AM

add_weeks

{{ startdate | add_weeks: 3 }}
9/30/2009 12:00:00 AM
{{ startdate | add_weeks: -7 }}
7/22/2009 12:00:00 AM

add_months

{{ startdate | add_months: 3 }}
12/9/2009 12:00:00 AM
{{ startdate | add_months: -10 }}
11/9/2008 12:00:00 AM

add_years

{{ startdate | add_years: 3 }}
9/9/2012 12:00:00 AM
{{ startdate | add_years: -1 }}
9/9/2008 12:00:00 AM

Related

{% add_stylesheet %}

Add a stylesheet asset to the head of the current page via a <link> tag

{% add_javascript %}

Add a script asset to the current page via a <script> tag

{% add_javascript inline %}

Outputs javascript code in an inline script

{% add_stylesheet inline %}

Outputs an inline stylesheet in a <style> tag.

add_days filter

Return a date object operand days in the future from the input date.

add_days: Integer operand

If operand is negative, return a date that many days in the past from the input date.

Examples

Use the add_seconds, add_minutes, add_hours, add_days, add_weeks, add_months, and add_years filters to manipulate dates.

Use math to manipulate dates

Copy
{% var startdate = '2009-09-09T00:00:00Z' | to_timezone: 'UTC' %}

add_seconds

{{ startdate | add_seconds: 3 }}
9/9/2009 12:00:03 AM
{{ startdate | add_seconds: -10239 }}
9/8/2009 9:09:21 PM

add_minutes

{{ startdate | add_minutes: 3 }}
9/9/2009 12:03:00 AM
{{ startdate | add_minutes: -180 }}
9/8/2009 9:00:00 PM

add_hours

{{ startdate | add_hours: 3 }}
9/9/2009 3:00:00 AM
{{ startdate | add_hours: -32 }}
9/7/2009 4:00:00 PM

add_days

{{ startdate | add_days: 3 }}
9/12/2009 12:00:00 AM
{{ startdate | add_days: -2 }}
9/7/2009 12:00:00 AM

add_weeks

{{ startdate | add_weeks: 3 }}
9/30/2009 12:00:00 AM
{{ startdate | add_weeks: -7 }}
7/22/2009 12:00:00 AM

add_months

{{ startdate | add_months: 3 }}
12/9/2009 12:00:00 AM
{{ startdate | add_months: -10 }}
11/9/2008 12:00:00 AM

add_years

{{ startdate | add_years: 3 }}
9/9/2012 12:00:00 AM
{{ startdate | add_years: -1 }}
9/9/2008 12:00:00 AM

Related

{% add_stylesheet %}

Add a stylesheet asset to the head of the current page via a <link> tag

{% add_javascript %}

Add a script asset to the current page via a <script> tag

{% add_javascript inline %}

Outputs javascript code in an inline script

{% add_stylesheet inline %}

Outputs an inline stylesheet in a <style> tag.

date filter

Returns the input as a date. If format is specified, converts the date to a string before returning it using the given format. The format must be a valid standard or custom .NET date format.

date: String format

If the input is already a date object, it will be used as-is - either to be formatted or returned without alteration. If the input is a number, it will be interpreted as a unix timestamp - that is the seconds since the Unix Epoch (midnight on January 1, 1970 UTC). If the input is not already a date and is not a number, it will attempt to parse it as the string representation of a date. If the input cannot be converted to a date using any of the previous methods, it will use the current date and time - which will prevent the page from being fast-cached. In all cases where the date filter creates a new date object, it uses the current timezone - which defaults to the site&#39;s timezone but may be set explicitly using the {% set_timezone %} method.

Examples

You can use the date filter either to create a date object or to format a date as a string.

Many ways to use the date filter

Copy
{% set_timezone 'UTC' %}

create a date object

{{ "2009-09-09" | date }}
9/9/2009 12:00:00 AM
{{ "2009-09-09" | date: "D" }}
Wednesday, September 9, 2009
{{ 0 | date: "D" }}
Thursday, January 1, 1970
{{ 1756239994 | date: "D" }}
Tuesday, August 26, 2025

Defaults to the current date

{{"now" | date}}
2009-09-09T00:00:00.0000000+00:00 (or whatever the current date is)

format a date as a string

{{request.date | date: "d"}}
9/9/2009
{{request.date | date: "D"}}
Sunday, September 9, 2009
{{request.date | date: "o"}}
9/9/2009 12:00:00 AM
{{request.date | date: "MMMM dd, yyyy"}}
September 09, 2009

Related

{{ date }}

A field containing a user-selected date

{{ date_field }}

Should be used to display a date field inside a form.

midnight filter

Return the input as a date at midnight of the same day. That is, with hours, minutes, and seconds set to 0.

midnight

Examples

Use the midnight filter to get the input as a date at midnight.

Using the midnight filter

Copy
{{ request.date | midnight }}
2009-09-09T00:00:00.0000000+00:00 (or whatever the current date is)
{{ "2020-02-26 14:42:02" | midnight }}
2/26/2020 12:00:00 AM
{{ 256 | midnight }}
1/1/1970 12:00:00 AM
{{ 1756239994 | midnight }}
8/26/2025 12:00:00 AM

Related

time_diff filter

If format is unspecified, returns a time_diff object describing the difference between the current date and the other date. If format is specified, converts the time difference to a string before returning it using the given format. If supplied, the format must be a valid standard or custom .NET TimeSpan format.

time_diff: time otherString format

Examples

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

How to use the format filter to format time diffs

Copy
{% var startdate = '2009-09-09 14:00:00Z' | date | to_timezone: 'America/New_York' %}
{% var enddate = '2009-09-10 17:32:00Z' | date | to_timezone: 'America/New_York' %}
{% var diff = startdate | time_diff: enddate %}

Format a time diff as a constant time span string

{{ diff | format: "c" }}
-1.03:32:00
Formats a time diff as a constant time span string (c = constant time span).

Format a time diff as a compact time span string

{{ diff | format: "g" }}
-1:3:32:00

Format a time diff using a custom .NET TimeSpan format string

{% if diff.total_seconds < 0 %}-{% endif %}{{ diff | format: "d' days, 'h' hours, and 'm' minutes'" }}
-1 days, 3 hours, and 32 minutes
Formats a time diff using a custom .NET TimeSpan format string. Since custom .NET TimeSpan format strings do not have a way to output the minus sign for negative time spans, you have to check for negative time spans separately.

Demonstrates how to time diff.

Time diff

Copy
{%- var diff = request.date | time_diff: calendarEntry.start_date -%}
{%- var is_future = true -%}
{%- if diff.total_seconds < 0 -%}
{%- set is_future = false -%}
{%- endif -%}
This event {% if is_future %}will start in{% else %}started{% endif -%}
{%- if diff.days > 0 %}{{diff.days }} days{% endif -%}
{%- if diff.hours > 0 %}{{diff.hours }} hours{% endif -%}
{%- if diff.minutes > 0 %}{{diff.minutes }} minutes{% endif -%}
{%- if diff.hours == 0 and diff.seconds > 0 %}{{diff.seconds }} seconds{% endif -%}
{%- unless is_future %}ago{% endunless -%}

Related

{{ time_diff }}

Contains information about the difference between two dates.

{{ time }}

Represents a specific instant in a specific timezone.

timezone filter

Returns the timezone that the date is in. If full is true or if an abbreviated timezone name is not available, returns the full timezone identifier (eg: &quot;Europe/Rome&quot;). If full is false (default) or not specified and an abbreviated timezone name is available returns the abbreviated timezone name (eg: &quot;PST&quot; or &quot;PDT&quot;).

timezone: Boolean full

Examples

Use the timezone filter to output the timezone used by a date object. The output may either be the full timezone identifier or the shortened timezone abbreviation.

Using the timezone filter

Copy
{{request.date | timezone}}
EST
{{request.date | add_months: 6 | timezone}}
EDT
{{request.date | timezone: true}}
America/Indiana/Indianapolis

Related

{{ timezone }}

Go to to_timezone filter filter documentation

List Filters

compact filter

Removes all null, empty, and invalid (is_valid == false, empty lists, etc..) objects from the list.

compact

Related

concat filter

Adds all of the items from the other list onto the end of the input list.

concat: list other

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.

Examples

Use the concat filter to join multiple lists together

Joining lists together

Copy
{% "a" | concat:"b" | json_encode %}
["a", "b"]

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

Related

first filter

Returns the first item in the input list

first

If the input is not a list, it will be returned without modification.

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

last

{{input | last}}
d

square bracket

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

Related

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

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.

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 -%}
<p>{{ group.Key.title }}: {{ group.Value | size }}</p>
{%- endfor -%}
<p>General Blog: 22</p>
<p>Announcements: 10</p>
<p>Events: 8</p>

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

Related

{{ group_field }}

Should be used to display a group of fields inside a form.

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

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.

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

Related

Go to index filter filter documentation

join filter

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

join

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.

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

Related

map filter

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

map: String property

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.

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: '<br />' }}

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

Related

{% map %}

Creates a new list of strings from the output when a block of liquid markup is executed for each item in a list or collection.

Go to rand filter filter documentation

Go to size filter filter documentation

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

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.

Examples

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

Removing duplicates from a list

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

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

Related

last filter

Returns the last item in the input list

last

If the input is not a list, it will be returned without modification.

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

last

{{input | last}}
d

square bracket

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

Related

Go to last_index filter filter documentation

last_index filter

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.

last_index: object findInteger startBoolean ignorecase

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.

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

Related

Go to reverse filter filter documentation

shuffle filter

Sorts the input list randomly. Unless prevent_cache is false, the shuffle filter will prevent the page from being fast-cached.

shuffle: Boolean prevent_cache

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.

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

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

Related

Go to slice filter filter documentation

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 &quot;random&quot; to sort the list in a random order - which is functionally identical to using the shuffle filter.

sort: String propertyBoolean ignorecase

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.

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

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

Related

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 &quot;random&quot; 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.

sort_natural: String property

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.

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

Related

Go to times filter filter documentation

Go to split filter filter documentation

where filter

Returns a new list which only contains items from the input list where the property has the specified value.

where: String propertyobject valueBoolean ignorecase

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.

Examples

Use the where and where_exp filters to get a new list containing only the items from the input list that match the provided condition.

Filtering lists

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

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

Related

where_exp filter

Returns a new list which only contains items from the input list that match the given expression when the item is referenced as name.

where_exp: String nameString expression

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.

Examples

Use the where and where_exp filters to get a new list containing only the items from the input list that match the provided condition.

Filtering lists

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

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

Related

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}}
EAAAAIhwZI7hYpsYH7BdFMcQB+H31bacn2V1LECVVhc7OLWWgQdK6S641eAt2Rp2JixOvCTO0ArVkXzhIL988jVDL+w=

decrypt_aes

{{securetext | decrypt_aes: secret, salt }}
I want this to be reasonably secure

Related

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}}
EAAAAIhwZI7hYpsYH7BdFMcQB+H31bacn2V1LECVVhc7OLWWgQdK6S641eAt2Rp2JixOvCTO0ArVkXzhIL988jVDL+w=

decrypt_aes

{{securetext | decrypt_aes: secret, salt }}
I want this to be reasonably secure

Related

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 }}
Pj4+IGRvIHlvdSB3YW50IHRvIHN0b3A/

base64_decode

{{ 'Pj4+IGRvIHlvdSB3YW50IHRvIHN0b3A/' | base64_decode }}
>>> do you want to stop?

base64_url_safe_encode

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

base64_url_safe_decode

{{ 'Pj4-IGRvIHlvdSB3YW50IHRvIHN0b3A_' | base64_url_safe_decode }}
>>> do you want to stop?

Related

{% image_url %}

Resolves the URL for an image with the desired presets and other settings applied.

{{ url }}

Field containing a URL.

{% set_canonical_url %}

Sets the canonical URL for the current page, which is output by default as part of an HTML page's {{ automatic_markup }}.

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 }}
Pj4+IGRvIHlvdSB3YW50IHRvIHN0b3A/

base64_decode

{{ 'Pj4+IGRvIHlvdSB3YW50IHRvIHN0b3A/' | base64_decode }}
>>> do you want to stop?

base64_url_safe_encode

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

base64_url_safe_decode

{{ 'Pj4-IGRvIHlvdSB3YW50IHRvIHN0b3A_' | base64_url_safe_decode }}
>>> do you want to stop?

Related

{% image_url %}

Resolves the URL for an image with the desired presets and other settings applied.

{{ url }}

Field containing a URL.

{% set_canonical_url %}

Sets the canonical URL for the current page, which is output by default as part of an HTML page's {{ automatic_markup }}.

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 }}
Pj4+IGRvIHlvdSB3YW50IHRvIHN0b3A/

base64_decode

{{ 'Pj4+IGRvIHlvdSB3YW50IHRvIHN0b3A/' | base64_decode }}
>>> do you want to stop?

base64_url_safe_encode

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

base64_url_safe_decode

{{ 'Pj4-IGRvIHlvdSB3YW50IHRvIHN0b3A_' | base64_url_safe_decode }}
>>> do you want to stop?

Related

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 }}
Pj4+IGRvIHlvdSB3YW50IHRvIHN0b3A/

base64_decode

{{ 'Pj4+IGRvIHlvdSB3YW50IHRvIHN0b3A/' | base64_decode }}
>>> do you want to stop?

base64_url_safe_encode

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

base64_url_safe_decode

{{ 'Pj4-IGRvIHlvdSB3YW50IHRvIHN0b3A_' | base64_url_safe_decode }}
>>> do you want to stop?

Related