List of supported handlebars helpers that can be used in a template to format data or add conditions on the data passed in workflow trigger.
SuprSend template editor uses handlebars templating language to add variables and support conditional content rendering in a template. You can find the list of inbuilt handlebars helpers here.Apart from the inbuilt helper functions, we have also created some custom helper functions which you can use in template editors.
Not supported in SMS and Whatsapp:Since, SMS (in India) and Whatsapp require pre-approved templates to send messages, we can’t support conditional content rendering in SMS and Whatsapp templates. You can use handlebars helpers if you are sending SMS in US with vendors like Twilio and Messagebird.
Can be used to add a default value if the variable values are " " , null , undefined.
Copy
Ask AI
{{default variable "default_value" }}
Returns:
Variable value if the variable value is present. For instance, the above example with data {"name":"Joe"} will return Joe
Default value if variable value is in " " , null , undefined. For instance, the above example with data {"name":""}, {"name":null} or {"city":"Bangalore"} will return user
Can be used to show some content in the template based on a condition. For email, you can use display condition to show or hide a particular content block
Copy
Ask AI
{{#compare name '==' "Mike"}}true_block{{else}}false_block{{/compare}}
Returns:
Returns if the condition inside compare statement returns truthy value. For instance, the above example with data{"candidate_count":1}will returnis
Returns (in case else statement is present) if the condition inside compare statement returns falsy value. For instance, Example-1 with data{"candidate_count":3}will returnare
or Returns if the else statement is not present. For instance, Example-2 with data{"candidate_count":3}will not return anything
Supported Conditional operators in compare statement:
Operator
Returns truthy when
Sample Statement
==
LHS equals RHS
1 == “1”
===
LHS value as well as data type matches with RHS
1 === 1
>
LHS is greater than RHS
2 > 1
\<
LHS is less than RHS
1 \< 2
>=
LHS is greater than equals to RHS
2 >= 2 or 3 >= 2
\<=
LHS is less than equal to RHS
2 \<= 2 or 1 \<= 2
!=
LHS is not equal RHS
3 != 1
!==
LHS value or data type does not equal RHS
1 !== “1”
Builtin helpers and custom helpers in handlebars can only work with nested objects if the value of parent key is present.For instance, {{default place.city "San Francisco"}} will return "San Francisco" only if place key is present, that is {"place":[]}
However, you can use the nested if condition to check if the parent is present and if so, then render nested objects value. Refer below example:
should be a date or timestamp. It will throw an error for invalid date format. To get today’s date (date on which template is getting rendered) you can use "now" string.
format string
mandatory
date string defining the format in which date should be printed. See all formatting options here. e.g. “dddd, MMMM Do YYYY, h:mm:ss a” will return datetime as “Sunday, February 14 2010, 3:25:50 PM”
timezone
optional
you can add timezone as a third parameter to convert time in a given timezone. See the list of all possible timezones here
Examples:
Example
Output
{{datetime-format date "ddd, MMM Do YYYY, h:mm:ss a"}}
Tue, Sep 26th 2023, 12:00:00 am
{{datetime-format date "[Today is] dddd"}}
Today is Tuesday
{{datetime-format date "Do MMMM, YYYY" "America/Chicago"}}
Coverts any type of JSON input to a string. Can be used to print JSON and array directly in templates without having to convert it into individual strings. One of the common use case is to pass complete JSON in Inbox template -> custom JSON field to generate custom UI.
Returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend. This helper will throw an error if it encounters an input value that is not a number or if the divisor is 0.
should be an array. If not helper function will throw an error.
key_string
mandatory only if items in the array are objects. If a unique operation needs to be performed on nested objects, then object notation (a.b or a[‘b’]) can be used.
Returns item at a particular index in the array. It can be useful in scenarios where you want to display a message like liked by Mike and 3 others.
Copy
Ask AI
{{itemAt variable index }}
Parameter
Description
variable
should be an array else the helper function will throw an error.
index
should be an integer else the helper function will throw an error.
Examples:
Example
Output
{{itemAt email 1}}
steve@abc.com
Note:This helper only works with an array of primitive data types like string, boolean, etc. If you have an array with objects in it, you can combine it with a unique helper to return the indexed value of a particular key inside the object. For instance, {{itemAt (unique array "city") 0}} in above mock will return San Francisco.
Concatenates all the values in an array, using a specified separator string between each value.
Copy
Ask AI
{{join variable "separator"}}
Parameter
Description
variable
should be an array and items in the array should be of primitive data types like string, number, etc, else the helper function will throw an error.
separator
should be string else by default separator , will be used. If not provided , is used.
Examples:
Example
Output
{{join email }}
joe@abc.com , steve@abc.com , joe@abc.com
{{join email ' - '}}
joe@abc.com - steve@abc.com - joe@abc.com
Note:This helper only works with an array of primitive data types like string, boolean, etc. If you have an array with objects in it, you can combine them with a unique helper to join the value of a particular key inside the object. For instance, {{join (unique array "city")}} in above mock will return San Francisco, Austin
Can be used to get the number of items in an array or the character length of a string. It can be useful in scenarios where you want to display a message like your post has got 100 likes.
Copy
Ask AI
{{length variable}}
Property
Description
variable
should be an array or string to get the actual count of items in the variable provided, else it returns 0.
Examples:
Example
Output
{{length array}}
3
{{length name}}
6
{{length active}}
0
We are adding further helpers to this list. If you have a use case that is not covered, ping us on our Slack Support Channel