Template Examples

Using variable paths that contain spaces in their names

Let’s assume a brick produces an output called @userPreferences and you want to reference the favorite color in a text template.

In the Page Editor Data Panel, the Output Data Tab might show:

Example Output Tab of the Data Panel showing data with names that include spaces.

To use the favorite color in a text template expression, you must use square brackets and quotation marks:

Your favorite color is {{ @userPreference.data["favorite color"] }}

Text substitution using the replace filter

To replace all occurrences of a word or phrase, use the replace filter. For example, to replace all occurrences of bricks with brix:

{{ @description | replace("bricks", "brix") }}

Chaining multiple filters in an expression

You can chain multiple filters using the | pipe operator. For example:

{{ "Lorem ipsum dolor sit amet" | truncate(15) | title }}

Will produce the following text output:

Lorem Ipsum...

Looping over elements of an array

You can use the for tag to loop over elements of an array. This is handy for creating bulleted lists in inputs that support Markdown, such as the Render Markdown brick

{% for @item in @items %}
- {{ @item }}
{% endfor %}

Last updated