Handlebars in five minutes
Handlebars is the template engine behind Asgard's Template mode, letting you produce dynamic text with concise syntax.
The basics
Handlebars inserts dynamic content with braces, and there are two forms:
Double braces versus triple braces
Double braces {{}} — HTML escaped
Triple braces {{{}}} — not escaped
| Syntax | Purpose | HTML escaping | Example |
|---|---|---|---|
{{}} | Ordinary text output | ✅ escaped | {{content}} → <script> |
{{{}}} | Raw output | ❌ not escaped | {{{content}}} → <script> |
What to use in Asgard
In Asgard, use triple braces {{{}}} in most cases, because:
- It avoids unintended conversion: special characters are not mangled (
<becoming<, say) - It keeps data intact: the variable's content comes out as it went in
Output:
Hello Alice! Your order number is ORD20240115001
📖 Learning the syntax properly
The full Handlebars syntax is in the official documentation
Core syntax
Inserting a variable
Conditionals
Loops
Asgard's built-in helpers
Asgard provides eight helpers:
Worked examples
A basic message template
A button template
{
"type": "BUTTON",
"title": "{{{user.name}}}'s details",
"text": "Membership details:\n{{{toJson user}}}",
"buttons": [
{
"label": "See the history",
"action": {
"type": "MESSAGE",
"text": "Show the conversation history"
}
}
]
}
An API query
Choosing between Template and Expression
| Situation | Use | Why |
|---|---|---|
| Text templates | Template | Concise syntax |
| Complex computation | Expression | The whole of JavaScript |
| Conditionals | Template | Built in |
| Arithmetic | Expression | More flexible |
Quick checklist
✅ Insert a variable: {{{variable}}}
✅ Conditional: {{#if condition}}
✅ Loop: {{#each array}}
✅ Asgard helpers: eight of them
✅ Object properties: {{{user.name}}} for nested access
Going further
Standard Handlebars syntax plus Asgard's helpers is enough to build capable dynamic message templates.