Skip to main content
Use a template with expressions and filters to render output based on the supplied data. The output can be passed to an optional mapper. If no output is produced the value for the key in the destination field will set to an empty string.

Fields

Template

The template supports several tags and filters. Rendering of data or using filters is done through {{ }} and {% %} tags.

The following tags are supported:

if

An if statement used for decision-making, if a certain condition is met output can be rendered. More complex conditions can be created with and and or.
{% if data.stock > 0 %}
    Stock: {{ data.stock }}
{% else %}
    Our product is out of stock.
{% endif %}

for

Used to loop over a set of items.
{% for user in users %}
    {{ user.username }}
{% endfor %}

The following filters are supported:

abs

The abs filter returns the absolute value.
{{ number|abs }}

batch

Filter items from a set into batches. Arguments:
  • size: How many items should each batch contain
  • fill: Missing items will show this text
  • preserve_keys: Whether to preserve keys or not (defaults to true)
For example `['a', 'b', 'c', 'd']` can be batched to always return 3 rows

    {% for row in items|batch(3, 'No item') %}
        <parent-tag>
            {% for index, column in row %}
                <example-tag>{{ index }} - {{ column }}</example-tag>
            {% endfor %}
        </parent-tag>
    {% endfor %}
    
Will result in:

    <parent-tag>
        <example-tag>0 - a</example-tag>
        <example-tag>1 - b</example-tag>
        <example-tag>2 - c</example-tag>
    </parent-tag>
    <parent-tag>
        <example-tag>0 - d</example-tag>
        <example-tag>1 - No item</example-tag>
        <example-tag>2 - No item</example-tag>
    </parent-tag>

capitalize

Capitalize the first value.
{{ 'template transformer'|capitalize }}

Template transformer

default

Return the supplied default value if the variable is empty or not defined.
{{ var|default('var is not defined') }}

escape (e)

Warning: Using this function doesn’t guarantee the input is safe in all contexts. Ensure untrusted input isn’t used in sensitive contexts.
Escape or the shorthand e can be used to escape text based on a supplied strategy.
{{ user.username|escape }}
or
{{ user.username|e }}

first

Returns the first item in a set.
number: {{ [1, 2, 3, 4]|first }}

number: 1

format

Format text based on with placeholders.
<example-tag>{{ "Value for a: %s and value for b: %s"|format("1", product.sku) }}</example-tag>

<example-tag>Value for a: 1 and value for b: SOME-SKU-123</example-tag>

join

Joins a list of items into a single string based on first argument, the second argument is used for the last item.
{{ [1, 2, 3]|join(', ', ' and ') }}

1, 2 and 3

keys

Returns the keys of a set of items.
{% for key in {a: 'a_value', b: 'b_value'}|keys %}
    {{ key }}
{% endfor %}

a b

last

Returns the last item in a set.
number: {{ [1, 2, 3, 4]|last }}

number: 4

length

Returns the number of items in a set.
{% if products|length > 10 %}
    ...
{% endif %}

lower

Convert text to lowercase.
{{ 'SKU'|lower }}

sku

nl2br

Change new lines to break rule tags <br />
{{ "Some text.\nThe next line."|nl2br }}

Some text.<br />
The next line

number_format

Format a number based on the arguments:
  • decimal: The number of decimal points to display
  • decimal_point: The character(s) to use for the decimal point
  • thousand_sep: The character(s) to use for the thousands separator
{{ -9800.333|number_format(2, '.', ',') }}

-9

{{ (1 + 0.2)|number_format(2) }}

1.20

replace

Replace text value based on a set of search and replace criteria.
<example-tag>{{ "Value for a: %stock% and value for b: %sku%"|replace({'%stock%': 1, '%sku%': "SOME-SKU-123"}) }}</example-tag>

<example-tag>Value for a: 1 and value for b: SOME-SKU-123</example-tag>

reverse

Reverse the order of a set of items.
{% for product in products|reverse %}
    ...
{% endfor %}

round

Round a number to the desired amount of decimals. Arguments:
  • precision: Precision to round to. 0 for whole numbers.
  • method: common (default) round up or down. ceil always round up and floor always round down.
{{ 42.55|round }}
43

{{ 42.55|round(1, 'floor') }}
42.5

striptags

Strip tags SGML/XML and replace adjacent whitespace characters by one space. As an argument tags can be supplied that should not be stripped from the data.
{{ some_html|striptags('<br><p>') }}

title

Capitalize every word in the supplied text.
{{ 'template transformer'|title }}

Template Transformer

trim

Remove whitespace data.
  • character_mask: The characters to strip
  • side: The default is to strip from the left and the right (both) sides, but left and right will strip from either the left side or right side only
 {{ '  Padded text.  '|trim }}

'Padded text'

{{ '  Padded text'|trim('.') }}

'  Padded text'

{{ '  Padded text  '|trim(side: 'left') }}

'Padded text  '

{{ '  Padded text  '|trim(' ', 'right') }}

'  Padded text'

upper

Convert text to uppercase the text.
{{ 'sku'|upper }}

SKU

url_encode

Convert characters in a text to their url percent equivalent (e.g. becomes %20)
{{ "path-seg*ment"|url_encode }}
path-seg%2Ament

{{ "string with spaces"|url_encode }}
string%20with%20spaces

{{ {'sku': 'SKU001', 'type': 'product'}|url_encode }}
name=SKU001&city=product

Variables

A set of key value pairs that used to make data available for the template when rendering.

Destination

The output of the template will be placed in the destination path

Mappers

Mappers can be used to structure the template output.