Variable Interpolation Filters

String Filters

lower

Transforms a string to lowercase.

upper

Transforms a string to uppercase.

capitalize

Transforms a string to be capitalized. The first character will be uppercase, all others lowercase.

title

Transforms a string to titlecase. Each word will be capitalized.

trim

Transforms a string by removing whitespace (default) from the beginning and end.

slug

Transforms a string into a url safe string which includes only ASCII chars and separates word with -.

replace

Transforms a string by substituting a substring with another one.

indent

Transforms a string by adding spaces before each new line.

slice

Transforms a string by extracting a substring.

default

Transforms an empty string by substituting with a default value.

url_encode

Transforms a string by percent encoding as a URL segment.

json_encode

Transforms a string to its JSON representation.

yaml_encode

Transforms a string to its YAML representation.

Examples

Having a project with the name: the QUICK brown project

InputOutput
{{ project.name | lower }}the quick brown project
{{ project.name | upper }}THE QUICK BROWN PROEJCT
{{ project.name | capitalize }}The quick brown project
{{ project.name | title }}The Quick Brown Project
{{ (' '~project.name~' ') | trim }}the QUICK brown project
{{ (project.name~'š') | slug }}the-QUICK-brown-projects
{{ project.name | replace({'brown': 'green'}) }}the QUICK green project
{{ project.name | indent(4) }} the QUICK brown project
{{ project.name | slice(4,5) }}QUICK
{{ project.name2 | default('Empty or undefined') }}Empty or undefined
{{ project.name | url_encode }}the%20QUICK%20brown%20project
{{ project.name | json_encode }}"the QUICK brown project"
{{ project.name | yaml_encode }}the QUICK brown project

Collection Filters

merge

Merges two or more collections.

For sequences, new values are added at the end of the existing ones.

For mappings, the merging process occurs on the keys. New values will be added or will overwrite existing keys.

## Sequences add new values as the end of existing ones
{{
  [1, 2] | merge([3, 4])
}}
# equals
[1, 2, 3, 4]

## Mappings will merge by overriding keys
{{
  {"a": "apple", "g": "grape"} | merge({"b": "banana", "g": "grapefruit"})
}}
# equals
{"a": "apple", "g": "grapefruit", "b": "banana"}

slice

Transform a collection by extracting a slice.

Arguments:

  • start: The start of the slice
  • length: The size of the slice
{{
  [1, 2, 3, 4] | slice(1, 2)
}}
# equals
[2, 3]

default

Transform an empty collection by substituting with a default value.

{{
  [] | default(["a", "new", "collection])
}}
# equals
["a", "new", "collection"]

url_encode

Encodes a collection as a URL query string.

{{
  {"page": 1, "search": "bunnyshell"} | url_encode
}}
# equals
page=1&search=bunnyshell

json_encode

Encodes a collection by marshalling to a json string.

yaml_encode

Encodes a collection by marshalling to a yaml string.

Arguments:

  • start: The start of the slice
  • length: The size of the slice
{{
  {"page": 1, "search": "bunnyshell"} | yaml_encode({indent: 2, inline: true})
}}
# equals
  {"page": 1, "search": bunnyshell}

kv_encode

Encodes a collection by marshalling to a key-value string.

Arguments:

  • indent: Indentation level of resulting KV string. Default: 0
  • indent_with: Indentation character. Default (space)
  • glue: KV separator string. Default =
{{
  {"page": 1, "search": "bunnyshell"} | kv_encode({glue: " = "})
}}
# equals
page = 1
search = bunnyshell

Date Filters

date

Format a date to a given format

Arguments:

  • format The date format. Default F j, Y H:i will render as July 4, 2024 18:07
  • timezone The date timezone. Default UTC
{{
  "now"|date('Y-m-d')
}}
# equals
2024-07-04

date_modify

{{
  "now"|date_modify('+1 day')|date('Y-m-d')
}}
# equals
2024-07-05