# Variable templating

Variable templating allows you to dynamically insert answers collected from your flow into other content, such as question labels and redirects. This enables a more personalized and dynamic user experience.

### Inserting Answer Values into Content

You can reference any previously collected answer by wrapping its variable name in double curly braces:

```
Hello, {{first_name}}!
```

If the user entered **Susana** as their `first_name`, the above would render as:

```
Hello, Susana!
```

This syntax is similar to templating systems like **Mustache** or **Handlebars**.

{% hint style="info" %}

#### Important Behavior to Know

* **Templated variables must be defined before use.**\
  Formsort does not allow referencing variables on steps that come **before** the variable is collected.
* **If a variable is missing, its name will be shown as-is.**\
  For example: `Hello, {{first_name}}!` will render exactly like that if `first_name` hasn’t been defined.
  {% endhint %}

***

### Where Variable Templating Works

Templating is most commonly used in text content (like question labels), but it’s supported almost everywhere across a flow. Some examples include (but are not limited to):&#x20;

#### Text and Question Labels

Personalize instructions and messages dynamically based on user input:

<div align="left"><figure><img src="/files/N54Pxaj17fUqsh06xYmt" alt="" width="381"><figcaption></figcaption></figure></div>

#### Redirect URLs

Redirect users to dynamic URLs based on their answers.

**Example:**\
Forward the user's name to the next destination:

&#x20;![](/files/KJBBYfgbCL7zSGOQOK5o)

***

### Template Formatting Functions&#x20;

Template functions let you format answer values before they are displayed, making your flow content cleaner and more user-friendly.

#### Using template functions <a href="#using-template-functions" id="using-template-functions"></a>

Sometimes raw answers—especially numbers—need formatting to be user-friendly. Template functions allow you to transform these values within your templates using the pipe symbol (`|`).

**Example:**\
You might have a variable called `product_price` from an API that returns a number:

```
Price: {{product_price}}.
```

If `product_price = 1499.95`, the result would be:

```
Price: 1499.95
```

This isn’t ideal for displaying prices. Instead, use the `usd` function to format the number as US dollars:

```
Price: {{product_price | usd}}.
```

This would render as:

```
Price: $1,499.95
```

Much better.

#### Chaining template functions <a href="#chaining-template-functions" id="chaining-template-functions"></a>

You can apply multiple formatting functions by chaining them with `|`.

**Example:**

```
Price: {{product_price | round | usd}}.
```

This first rounds the number, then formats it as currency:

```
Price: $1,500
```

### Available functions <a href="#available-functions" id="available-functions"></a>

Here’s a list of supported functions you can use within templates:

<table><thead><tr><th width="166.54547119140625">Function</th><th>Description</th></tr></thead><tbody><tr><td><code>capitalize</code></td><td>Capitalizes the first letter of a string.</td></tr><tr><td><code>ceil</code></td><td>Rounds <strong>up</strong> to the nearest integer.</td></tr><tr><td><code>default "text"</code></td><td>Displays fallback text if the variable is not defined. Example:<br><code>Allergies: {{allergies | default "none"}}</code></td></tr><tr><td><code>floor</code></td><td>Rounds <strong>down</strong> to the nearest integer.</td></tr><tr><td><code>get "key"</code></td><td>Gets a nested value from an object.<br>Example: <code>{{user_address | get "city"}}</code></td></tr><tr><td><code>label</code></td><td>Returns the <strong>label</strong> of a selected choice (useful with multiple choice questions).</td></tr><tr><td><code>lowercase</code></td><td>Converts text to lowercase.</td></tr><tr><td><code>round</code></td><td>Rounds to the nearest whole number.</td></tr><tr><td><code>uppercase</code></td><td>Converts text to UPPERCASE.</td></tr><tr><td><code>usd</code></td><td>Formats a number as US currency.<br><code>1499.95</code> → <code>$1,499.95</code></td></tr></tbody></table>

***

### Need More Customization?

If none of the built-in functions meet your needs:

* **Use a** [**calculated answer**](/response-data-collection-and-management/variable-schema/calculated-answers.md) to pre-format your value before inserting it into templates.
* **Have a feature request?** Reach out via chat—we’d love to hear what would help!


---

# 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.formsort.com/variable-templating.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.
