Template (Handlebars)
Ringkasan
Section titled “Ringkasan”Komponen Templates menyediakan templating berbasis Handlebars untuk menghasilkan konten dinamis.
Penggunaan Dasar
Section titled “Penggunaan Dasar”- id: format_message type: template config: template: "Hello, {{name}}! Your order #{{order_id}} is ready." next: send_messageSintaks Template
Section titled “Sintaks Template”Variabel
Section titled “Variabel”{{variable}}{{nested.property}}{{array.[0]}}Kondisional
Section titled “Kondisional”{{#if condition}} Content when true{{else}} Content when false{{/if}}
{{#unless condition}} Content when false{{/unless}}Perulangan
Section titled “Perulangan”{{#each items}} Item: {{this.name}} - ${{this.price}}{{/each}}
{{#each items as |item index|}} {{index}}. {{item.name}}{{/each}}Helper Bawaan
Section titled “Helper Bawaan”{{#with user}} Name: {{name}} Email: {{email}}{{/with}}
{{lookup items index}}
{{log "Debug message"}}Helper Kustom
Section titled “Helper Kustom”Helper String
Section titled “Helper String”{{uppercase text}} <!-- "HELLO" -->{{lowercase text}} <!-- "hello" -->{{capitalize text}} <!-- "Hello" -->{{truncate text 50}} <!-- "Hello wo..." -->Helper Angka
Section titled “Helper Angka”{{formatNumber 1234.56}} <!-- "1,234.56" -->{{currency amount}} <!-- "$99.99" -->{{percent value}} <!-- "85%" -->Helper Tanggal
Section titled “Helper Tanggal”{{formatDate date "YYYY-MM-DD"}}{{relativeTime timestamp}} <!-- "2 hours ago" -->{{now}} <!-- Current timestamp -->Contoh Template
Section titled “Contoh Template”Konfirmasi Pesanan
Section titled “Konfirmasi Pesanan”- 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"}}Pembaruan Status
Section titled “Pembaruan Status”- 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}}Template Eksternal
Section titled “Template Eksternal”Muat template dari file:
- id: render_email type: template config: template_file: "templates/email/welcome.hbs" data: user: "{{user}}" company: "Acme Corp"Partial
Section titled “Partial”Mendaftarkan Partial
Section titled “Mendaftarkan Partial”components: templates: partials: header: "templates/partials/header.hbs" footer: "templates/partials/footer.hbs"Menggunakan Partial
Section titled “Menggunakan Partial”{{> header}}
Main content here
{{> footer}}