Helpers in Templates
Our Template Service is built on top of Handlebars and extends its core functionality with a set of additional helpers.
On this page, you’ll find an overview of the available helpers, including their purpose, expected parameters, and usage examples.
For more information about standard Handlebars syntax and built-in helpers, refer to the official documentation: https://handlebarsjs.com/guide/
<h2>{{t 'greeting' name=@inputs.first_name}}</h2>
{{#if (or (and @inputs.has_permission @inputs.is_logged_in) (not @inputs.authentication))}}
<p>{{t 'dashboard_access_granted'}}</p>
<p>{{t 'balance'}}: {{number @inputs.balance}}</p>
{{else}}
<p>{{t 'dashboard_access_denied'}}</p>
{{/if}}Translation and internationalization
The t, number, currency, datetime, and relativetime helpers are language and time zone aware, using the template rendering context to determine formatting behavior.
{{t 'greeting' name=@inputs.first_name}}
{{t 'balance'}}: {{number @inputs.balance}}Language and time zone resolution
All formatting helpers use the language property from the resolve input:
The language is passed to the t helper (supported by i18next) to determine to which language the supplied localization key needs to be translated. A deeper explanation on how to localize strings in templates can be found in on the Localizations in Templates page.
This language is also passed internally to the corresponding Intl.* formatter and determines:
Number formatting (decimal separators, grouping) via
numberCurrency formatting (symbol placement, spacing) via
currencyDate and time formatting (month names, ordering, 12/24h clock) via
datetimeRelative time phrasing (e.g., “1 day ago”) via
relativetime
If no language is provided, "EN" is used.
The datetime helper additionally respects the timeZone property from the resolve input.
If provided, it is passed to Intl.DateTimeFormat.
If omitted, the time zone "UTC" is used.
Combining helpers
Subexpressions can be used to combine multiple helpers:
In this example, sum is used as a subexpression and is evaluated first inside round brackets (...), after which its result is passed as an argument to le.
This can also be used to construct if cases with combined and ,or and not
API reference
Translation and internationalization helpers
t
Translates a key using the current language (supports interpolation) See more in Localizations in Templates page.
Input:
Output: Dear,
datetime
Formats a date/time using locale and timezone (Intl.DateTimeFormat)
Input:
Output: Thu, January 01, 1970 at 12 AM
Logical helpers
and
Logical AND
(arg1 && arg2)
or
Logical OR
(arg1 || arg2)
not
Logical NOT
(!arg1)
Comparison helpers
eq
Checks equality
(arg1 == arg2)
ne
Checks inequality
(arg1 != arg2)
gt
Greater than
(arg1 > arg2)
ge
Greater than or equal
(arg1 >= arg2)
lt
Less than
(arg1 < arg2)
le
Less than or equal
(arg1 <= arg2)
Math helpers
sum
Adds all arguments together
Input: {{sum 2 3 4}}
Output: 9
subtract
Subtracts each next argument from the first
Input: {{subtract 10 3 2}}
Output: 5
multiply
Multiplies all arguments
Input: {{multiply 2 3 4}}
Output: 24
divide
Divides the first argument by the rest sequentially
Input: {{divide 20 2 2}}
Output: 5
mod
Returns remainder of a division (arg1 % arg2)
Input: {{mod 10 3}}
Output: 1
floor
Rounds a number down
Input: {{floor 4.8}}
Output: 4
ceil
Rounds a number up
Input: {{ceil 4.2}}
Output: 5
round
Rounds to the nearest integer
Input: {{round 4.5}}
Output: 5
Array helpers
length
Returns the length of an array
includes
Checks whether an array contains a value
join
Joins array elements using a separator
String helpers
includes
Checks whether a string contains a substring
length
Returns the length of a string
join
Joins multiple arguments using a separator (default ", ")
Object helpers
toJsonString
Serializes data into a JSON string. Because JSON may contain special characters, the way you render the output depends on the context.
If used in plain text or in HTML within a <script> tag, use triple braces ({{{ }}}) to prevent HTML escaping. Any mention of </script will also be replaced by <\/script to prevent the JSON from accidentally breaking out of the <script> tag.
Double braces ({{ }}) can be used if you want to render the JSON as text in HTML.
Last updated