Skip to main content

Handlebars Templating Guide

Handlebars is a templating language that lets you insert dynamic data and add logic to your templates. This guide covers the basics you need to write notification templates.

Understanding Handlebars

Handlebars uses double curly braces {{ and }} to mark placeholders where dynamic content will be inserted. For complete Handlebars documentation, see Handlebars Official Guide.

Basic Syntax

Variable Interpolation

Insert dynamic values into your templates using {{variableName}} syntax:
When this template renders, the placeholders are replaced with actual values from the event:

Conditional Logic

Use {{#if}} blocks to show content only when a condition is true:
This section only appears if the entity has an owner. If the field is empty, the entire block is hidden.

Else Blocks

Add {{else}} to provide alternative content:

Looping Through Lists

Use {{#each}} to iterate through arrays:
For each item in the tags array, this creates a list item. Use {{this}} to refer to the current item. With Object Properties:
Access properties of objects in the array. Looping Through Owners: An entity can have more than one owner, so entity.owners is a list. Each item has id, name, displayName, and type. Use the lowercase name entity.owners. Handlebars is case-sensitive, so entity.Owners renders nothing.
displayName can be empty for some owners. Use {{name}} if you need a value that is always set.
Combine conditional logic with loops to show content only when list items exist:

Nested Logic

You can nest conditions and loops:

Using Helpers

Helpers are functions that perform operations on your data. Collate provides 24 custom helpers beyond standard Handlebars features.

Basic Helper Syntax

Call helpers by name with arguments in parentheses:

Helpers with Parameters

Some helpers take parameters:

Nesting Helpers

Helpers can be nested:
This filters tests to show only failed ones, then limits the display to 5 items.
Use with to assign helper results to a variable for cleaner code:

Context Objects

Templates have access to special objects containing event and entity data:
  • event - The change event that triggered the notification
  • entity - The entity being notified about
  • subscription - Information about the event subscription
  • baseUrl - Base URL of your Collate instance
For detailed information about available properties, see Template Context Reference.

Common Patterns

Accessing Nested Properties

Use dot notation to access nested object properties:

Default Values with If

Show a default message when data is missing:

Formatting Output

Use helpers to format data:
Use the buildEntityUrl helper to create clickable links to entities:
This creates a link that opens the entity in Collate UI.

Important Notes

Property Access

Handlebars uses dot notation (.) to access properties:
  • entity.name - Access the name property
  • entity.owners.0.id - Access nested properties
  • entity.tags.0.name - Access array items by index

Empty String Rendering

If a property doesn’t exist or is empty, Handlebars renders an empty string:
If entity.description is missing, renders as:
Use conditionals to prevent this:

HTML Escaping

Double braces {{ }} escape HTML characters in the value. For example, < becomes &lt; and & becomes &amp;. Use them in the template body for plain-text values such as names. Triple braces {{{ }}} output the value with no escaping. Use them for content that is already HTML, such as the table from renderTableSample and rich-text descriptions:
A description saved in the Collate UI contains HTML tags, so with double braces the notification shows those tags as text. Email notifications remove unsafe tags such as <script>. The email subject is plain text, so escaped characters appear literally. For example, {{entity.name}} shows Sales &amp; Marketing for an entity named Sales & Marketing. Use triple braces for names in the subject:

Spaces in Output

Handlebars preserves whitespace and line breaks. Be careful with formatting:
Renders on its own line. To control spacing, use:

Next Steps