テンプレート (Handlebars)
Templates component は、動的コンテンツを生成するための Handlebars ベースのテンプレート機能を提供します。
基本的な使い方
Section titled “基本的な使い方”- id: format_message type: template config: template: "Hello, {{name}}! Your order #{{order_id}} is ready." next: send_messageテンプレート構文
Section titled “テンプレート構文”{{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 -->テンプレート例
Section titled “テンプレート例”- 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"}}ステータス更新
Section titled “ステータス更新”- 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}}外部テンプレート
Section titled “外部テンプレート”ファイルからテンプレートを読み込みます:
- id: render_email type: template config: template_file: "templates/email/welcome.hbs" data: user: "{{user}}" company: "Acme Corp"partials
Section titled “partials”Partial の登録
Section titled “Partial の登録”components: templates: partials: header: "templates/partials/header.hbs" footer: "templates/partials/footer.hbs"Partial の使用
Section titled “Partial の使用”{{> header}}
Main content here
{{> footer}}