# 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](https://mozilla.github.io/nunjucks/templating.html#for) 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](https://www.pixiebrix.com/marketplace/520b2dc6-11a9-4a9c-9753-58e3f2ed4513/render-markdown/)

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.pixiebrix.com/developing-mods/developer-concepts/text-template-guide/template-examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
