Handlebars
The Novu notification content editor relies on Handlebars.js to establish the logic and control flow of our workflows. For a deeper comprehension of Handlebars.js, you can refer to its documentation. This resource offers comprehensive insights into the utilization of Handlebars.js in crafting dynamic and adaptable notification content within the Novu platform.Novu-specific helpers
groupBy
groupBy helper is used to group the items in an array based on a property.
- Template
- Context
- Output
equals
equals helper allows you to perform comparisons, both for boolean expressions and string comparisons.
- Template
- Context
- Output
numberFormat
numberFormat helper is used to format numbers with specified decimal length, thousands separator, and decimal separator.
- Template
- Context
- Output
pluralize
Thepluralize helper allows you to easily handle pluralization in your templates by providing different forms of a word depending on a variable value.
Basic Usage
In its simplest form, thepluralize helper takes three arguments:
count: The numeric value that determines whether the singular or plural form should be used.singular: The singular form of the word.plural: The plural form of the word.
Example
dog_count is equal to 1, it will render “1 dog,” and if it’s greater than 1, it will render “dogs.”
Use Cases & Examples
Handling Event Count Display with Excluded Individuals
In some cases, you may want to display the total count of certain events but exclude specific individuals who are already mentioned. For example, when using a phrase like “John and{{step.total_count}} people liked your photo,” you may notice that the count is off by one because “John” is already mentioned.
To account for such scenarios, you can utilize the following approach:
step.events array and conditionally display each name. If it’s the first name in the list, it will be shown without “and.” For subsequent names, we add “and” before the last name. This ensures that the count is not affected by names that are explicitly mentioned in the message.
By using this code, you can achieve a more accurate representation of the event count in your messages, even when some users are individually mentioned in the message text.
Using array length as count
Array length be used as total number of item. For example, if paylod have fruits property of type array then its length can be used as total number of fruits.- Template
- Payload
- Output
In a future release, we plan to replace handlebar helpers with an alternative solution. Please note that custom handlebars in the editor itself are not currently supported. If we are missing any handlebar helper that is blocking you to write template for use case, feel free to reach out to us in discord