Variable templating
Personalize your flows by reusing answers you've collected.
Last updated
Was this helpful?
Personalize your flows by reusing answers you've collected.
Last updated
Was this helpful?
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.
You can reference any previously collected answer by wrapping its variable name in double curly braces:
If the user entered Susana as their first_name
, the above would render as:
This syntax is similar to templating systems like Mustache or Handlebars.
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.
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):
Personalize instructions and messages dynamically based on user input:
Redirect users to dynamic URLs based on their answers.
Example: Forward the user's name to the next destination:
Template functions let you format answer values before they are displayed, making your flow content cleaner and more user-friendly.
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:
If product_price = 1499.95
, the result would be:
This isn’t ideal for displaying prices. Instead, use the usd
function to format the number as US dollars:
This would render as:
Much better.
You can apply multiple formatting functions by chaining them with |
.
Example:
This first rounds the number, then formats it as currency:
Here’s a list of supported functions you can use within templates:
capitalize
Capitalizes the first letter of a string.
ceil
Rounds up to the nearest integer.
default "text"
Displays fallback text if the variable is not defined. Example:
Allergies: {{allergies | default "none"}}
floor
Rounds down to the nearest integer.
get "key"
Gets a nested value from an object.
Example: {{user_address | get "city"}}
label
Returns the label of a selected choice (useful with multiple choice questions).
lowercase
Converts text to lowercase.
round
Rounds to the nearest whole number.
uppercase
Converts text to UPPERCASE.
usd
Formats a number as US currency.
1499.95
→ $1,499.95
If none of the built-in functions meet your needs:
Have a feature request? Reach out via chat—we’d love to hear what would help!
Use a to pre-format your value before inserting it into templates.