Ir al contenido

Plantillas (Handlebars)

El componente Templates proporciona plantillas basadas en Handlebars para generar contenido dinámico.

- 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}}
{{#with user}}
Name: {{name}}
Email: {{email}}
{{/with}}
{{lookup items index}}
{{log "Debug message"}}
{{uppercase text}} <!-- "HELLO" -->
{{lowercase text}} <!-- "hello" -->
{{capitalize text}} <!-- "Hello" -->
{{truncate text 50}} <!-- "Hello wo..." -->
{{formatNumber 1234.56}} <!-- "1,234.56" -->
{{currency amount}} <!-- "$99.99" -->
{{percent value}} <!-- "85%" -->
{{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}}

Carga plantillas desde archivos:

- id: render_email
type: template
config:
template_file: "templates/email/welcome.hbs"
data:
user: "{{user}}"
company: "Acme Corp"
components:
templates:
partials:
header: "templates/partials/header.hbs"
footer: "templates/partials/footer.hbs"
{{> header}}
Main content here
{{> footer}}