模板(Handlebars)
Templates 组件基于 Handlebars 提供模板功能,用于生成动态内容。
- id: format_message type: template config: template: "Hello, {{name}}! Your order #{{order_id}} is ready." next: send_message{{variable}}{{nested.property}}{{array.[0]}}{{#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}}内置辅助函数
Section titled “内置辅助函数”{{#with user}} Name: {{name}} Email: {{email}}{{/with}}
{{lookup items index}}
{{log "Debug message"}}自定义辅助函数
Section titled “自定义辅助函数”字符串辅助函数
Section titled “字符串辅助函数”{{uppercase text}} <!-- "HELLO" -->{{lowercase text}} <!-- "hello" -->{{capitalize text}} <!-- "Hello" -->{{truncate text 50}} <!-- "Hello wo..." -->数字辅助函数
Section titled “数字辅助函数”{{formatNumber 1234.56}} <!-- "1,234.56" -->{{currency amount}} <!-- "$99.99" -->{{percent value}} <!-- "85%" -->日期辅助函数
Section titled “日期辅助函数”{{formatDate date "YYYY-MM-DD"}}{{relativeTime timestamp}} <!-- "2 hours ago" -->{{now}} <!-- Current timestamp -->- 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"}}- 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}}从文件加载模板:
- id: render_email type: template config: template_file: "templates/email/welcome.hbs" data: user: "{{user}}" company: "Acme Corp"注册局部模板
Section titled “注册局部模板”components: templates: partials: header: "templates/partials/header.hbs" footer: "templates/partials/footer.hbs"使用局部模板
Section titled “使用局部模板”{{> header}}
Main content here
{{> footer}}