Variable types and their syntax
Handlebars Helpers
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.default
Can be used to add a default value if the variable values are" " , null , undefined.
Returns:
- Variable value if the variable value is present. For instance, the above example with data
{"name":"Joe"}will returnJoe- Default value if variable value is in
" ",null,undefined. For instance, the above example with data{"name":""},{"name":null}or{"city":"Bangalore"}will returnuser
compare
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 blockReturns:Supported Conditional operators in compare statement:
- 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
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:
each
You can iterate over a static or dynamic length list using each helper. Inside the block, you add the array object key which you want to iterate over.
Returns: Above example for below mock data will return steve Olivia
datetime-format
Returns a formatted date string. This helper will throw error if an invalid date is provided.
Examples:
jsonStringify
Converts 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.variable should be a valid JSON input.
lowercase
This handlebar helper is used to convert string to lowercase. If non string values are provided empty string'' is returned.
uppercase
This handlebar helper is used to convert string to uppercase. If non string values are provided empty string'' is returned.
capitalize
This handlebar helper is used to capitalize the first character in provided string. If non string values are provided empty string'' is returned.
Math operators
add
Returns the sum of two operands. Both input values should be numbers, else it will throw an error.subtract
Returns the difference between two operands. Both input values should be numbers, else it will throw an error.multiply
Returns the product of two operands. Both input values should be numbers, else it will throw an error.divide
Returns the quotient of the left operand divided by the right operand. Both input values should be numbers; else it will throw an error.round
Returns the value of a number rounded to the nearest integer. The input value should be a number; else it will throw an error.mod
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.Array Operators
unique
Returns unique items in an array.
Examples:
itemAt
Returns item at a particular index in the array. It can be useful in scenarios where you want to display a message likeliked by Mike and 3 others.
Examples:
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.join
Concatenates all the values in an array, using a specified separator string between each value.
Examples:
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, Austinlength
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 likeyour post has got 100 likes.
Examples:
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
Frequently Asked Questions
We're seeing an issue where apostrophes (`'`) in push notification text are getting converted to `&`#x27;` in the preview.
We're seeing an issue where apostrophes (`'`) in push notification text are getting converted to `&`#x27;` in the preview.
This is happening because handlebars by default does url encoding, use triple curly braces syntax like
{{{ variable }}} whenever you need to print the value of the variable as is without any encoding.How does SuprSend avoid HTML injection when printing variables?
How does SuprSend avoid HTML injection when printing variables?
SuprSend uses the default syntax for variables
{{ var }} to print the value of the variable. This is HTML-escaped, so characters like <, >, ", ', & are converted into their HTML entity equivalents when rendered as text.