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
| Syntax | Purpose | Example |
|---|---|---|
{{variableName}} | Insert a value | {{entity.name}} |
{{#if condition}}...{{/if}} | Conditional display | {{#if entity.owner}}Owner: {{entity.owner}}{{/if}} |
{{#each array}}...{{/each}} | Loop through lists | {{#each entity.tags}}{{this}}{{/each}} |
{{helper arg1 arg2}} | Call a helper function | {{formatDate entity.updatedAt}} |
Variable Interpolation
Insert dynamic values into your templates using{{variableName}} syntax:
Conditional Logic
Use{{#if}} blocks to show content only when a condition is true:
Else Blocks
Add{{else}} to provide alternative content:
Looping Through Lists
Use{{#each}} to iterate through arrays:
{{this}} to refer to the current item.
With Object Properties:
Nested Logic
You can nest conditions and loops:Using Helpers
Helpers are functions that perform operations on your data. Collate provides 22 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:Context Objects
Templates have access to special objects containing event and entity data:event- The change event that triggered the notificationentity- The entity being notified aboutsubscription- Information about the event subscriptionbaseUrl- Base URL of your Collate instance
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:Building Links
Use thebuildEntityUrl helper to create clickable links to entities:
Important Notes
Property Access
Handlebars uses dot notation (.) to access properties:
entity.name- Access the name propertyentity.owner.id- Access nested propertiesentity.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:entity.owner is missing, renders as:
Spaces in Output
Handlebars preserves whitespace and line breaks. Be careful with formatting:Next Steps
- Explore Collate’s helpers → Custom Helpers Reference
- Learn available data → Template Context Reference