# Dynamic variables in templates

All template fields (except for Settings) can contain dynamic variables, which are added by inserting the variable name, surrounded by double (or triple) curly brackets. For example: {{name}} or {{email}}. The dynamic variables are replaced with the values passed through the parameters object of the SDK or API call. If the value of a certain variable is not passed, it will be replaced with an empty string.

Variables added with double brackets are escaped by default, so if you pass "<b>bold</b>" as "message" variable, {{message}} will be replaced with "&lt;b&gt;bold&lt;/b&gt;". If you want the variable to be injected without escaping (if HTML code is passed, for instance) use 3 brackets syntax, like this {{{my_html}}}. However, keep in mind that these variables are unsafe and can be abused.

You can also use one of our built-in variables: user_os, user_ip, user_platform, user_browser, user_version, user_country, and user_referrer.
Have a suggestion for additional built-in variables? Let us know!

The IP address (user_ip) is personal data and is protected by the GDPR compliance requirement. Therefore, the IP addresses are cached by the md5 algorithm.

The user's country (user_country) is an estimated location and cannot be guaranteed 100% accuracy.

# Restrictions

Please note that the total size of the dynamic variables cannot exceed 50kb except for attachment variables, whose total size is limited by the subscription plan.

Requests that exceed this threshold won't be processed. Feel free to pop up your questions.

# Conditional Rendering

If the template variable has falsy value, the section won't be rendered.

Template Params

{
  hasData: false,
}

Template

{{#hasData}}
The "if" section.
This section won't be rendered!
{{/hasData}}

{{^hasData}}
The "else" section. Optional.
This section will be rendered.
{{/hasData}}

# Nested Object

JavaScript's dot notation can be used to access keys that are properties of objects.

Template Params

{
  name: {
    first: 'Bob',
    last: 'Fanky',
  },
}

Template

{{name.first}} {{name.last}}

# Loop

If the variable's value is a list, the section will be repeated several times for each item.

The dot can be used to indicate an item of the array.

Template Params

{
  names: ['Bob', 'Larry', 'Alice'],
}

Template

{{#names}}
Render names {{.}}
{{/names}}

For the list of objects, the object property can be used instead of a dot.

Template Params

{
  persons: [
    { name: 'Bob' },
    { name: 'Larry' },
    { name: 'Alice' },
  ],
}

Template

{{#persons}}
 Hi {{name}}!
{{/persons}}