Templates (Handlebars)
Overview
Section titled “Overview”The Templates component provides Handlebars-based templating for generating dynamic content.
Basic Usage
Section titled “Basic Usage”- id: format_message type: template config: template: "Hello, {{name}}! Your order #{{order_id}} is ready." next: send_messageTemplate Syntax
Section titled “Template Syntax”Variables
Section titled “Variables”{{variable}}{{nested.property}}{{array.[0]}}Conditionals
Section titled “Conditionals”{{#if condition}} Content when true{{else}} Content when false{{/if}}
{{#unless condition}} Content when false{{/unless}}{{#each items}} Item: {{this.name}} - ${{this.price}}{{/each}}
{{#each items as |item index|}} {{index}}. {{item.name}}{{/each}}Built-in Helpers
Section titled “Built-in Helpers”{{#with user}} Name: {{name}} Email: {{email}}{{/with}}
{{lookup items index}}
{{log "Debug message"}}Custom Helpers
Section titled “Custom Helpers”String Helpers
Section titled “String Helpers”{{uppercase text}} <!-- "HELLO" -->{{lowercase text}} <!-- "hello" -->{{capitalize text}} <!-- "Hello" -->{{truncate text 50}} <!-- "Hello wo..." -->Number Helpers
Section titled “Number Helpers”{{formatNumber 1234.56}} <!-- "1,234.56" -->{{currency amount}} <!-- "$99.99" -->{{percent value}} <!-- "85%" -->Date Helpers
Section titled “Date Helpers”{{formatDate date "YYYY-MM-DD"}}{{relativeTime timestamp}} <!-- "2 hours ago" -->{{now}} <!-- Current timestamp -->Example Templates
Section titled “Example Templates”Order Confirmation
Section titled “Order Confirmation”- id: order_confirmation type: template config: template: | # Order Confirmation
**Order #{{order.id}}**
Hi {{customer.name}},
Thank you for your order!
## Items: {{#each order.items}} - {{name}} x {{quantity}} - ${{price}} {{/each}}
**Subtotal:** ${{order.subtotal}} **Tax:** ${{order.tax}} **Total:** ${{order.total}}
Expected delivery: {{formatDate order.delivery_date "MMMM D, YYYY"}}Status Update
Section titled “Status Update”- id: status_template type: template config: template: | {{#if is_complete}} Your request has been completed! {{else if is_pending}} Your request is being processed... {{else}} We've received your request. {{/if}}
{{#if notes}} Notes: {{notes}} {{/if}}External Templates
Section titled “External Templates”Load templates from files:
- id: render_email type: template config: template_file: "templates/email/welcome.hbs" data: user: "{{user}}" company: "Acme Corp"Partials
Section titled “Partials”Register Partial
Section titled “Register Partial”components: templates: partials: header: "templates/partials/header.hbs" footer: "templates/partials/footer.hbs"Use Partial
Section titled “Use Partial”{{> header}}
Main content here
{{> footer}}