Skip to content

Filters

The following filters were added to Contemplate. For a full list of filters available (including built-ins), use the debug() function:

echo "{{ debug() }}" | contemplate

base64encode

This base64-encodes a string or a list of bytes, returning a base64 encoded string.

Example:

{{ "Hello" | base64encode }}
{{ [0,0,0,0] | base64encode }}
SGVsbG8=
AAAAAA==

hexencode

This hex-encodes a string or a list of bytes, returning a hex encoded string.

Example:

{{ "Hello" | hexencode }}
{{ [0,0,0,0] | hexencode }}
48656c6c6f
00000000

from_json

Constructs an object from a JSON string.

Example:

The color is {{ ('{"color": "green"}' | from_json).color }}
The color is green

from_toml

Constructs an object from a TOML string.

Example:

The color is {{ ('color = "orange"' | from_toml).color }}
The color is orange

from_yaml

Constructs an object from a YAML string.

Example:

The color is {{ ('color: purple' | from_yaml).color }}
The color is purple

jsonpath

Queries an object using a JSONPath expression, returning a list of matching values.

Example:

{% set data = '{"users": [{"name": "Alice"}, {"name": "Bob"}]}' | from_json -%}
{% for name in data | jsonpath("$.users[*].name") %}
- {{ name }}
{%- endfor %}
- Alice
- Bob