تخطَّ إلى المحتوى

Templates (Handlebars)

component-templates renders Handlebars text from the current flow payload and message envelope. It is a small, deterministic component for formatting replies, reports, prompts, labels, and notification text before routing to the next flow step.

Use it when a flow needs string rendering, not when it needs a full HTML/email templating system. The current component exposes one operation, text, and one config object, templates.

Use the component through component.exec or through the dev flow generated by greentic-flow:

format_answer:
component.exec:
component: ai.greentic.component-templates
operation: text
input:
config:
templates:
text: "Hello {{payload.name}}. Your order #{{payload.order_id}} is ready."
routing: out
msg: "{{msg}}"
payload: "{{payload}}"
routing:
- out: true

The component manifest defines this config:

FieldRequiredDefaultPurpose
templates.textYes-Handlebars template to render.
templates.routingNooutOptional routing target returned with the component output.
templates.output_pathNotextDot path where the rendered string is stored when wrapping output.
templates.wrapNotrueWhen true, return an object; when false, return the rendered string directly.

The runtime input gives the template two top-level objects:

ObjectMeaning
payloadIncoming node payload. Use {{payload.name}}, {{payload.items}}, and similar paths.
msgChannel message envelope. Use this for message metadata such as tenant, session, channel, and provider values when present.

{{payload}} is normalized to compact JSON for debugging. Use triple braces to avoid HTML escaping:

Debug payload: {{{payload}}}

Standard Handlebars variables and built-in control flow work:

{{payload.user.name}}
{{#if payload.active}}
Active
{{else}}
Inactive
{{/if}}
{{#each payload.items}}
- {{this.name}} x {{this.quantity}}
{{/each}}

The current component does not register custom helpers such as uppercase, currency, formatDate, remote template loading, or partial files. If a workflow needs those, create a custom component with greentic-component wizard and add the helper behavior there.

Default wrapped output:

{
"payload": {
"text": "Hello Ada"
},
"routing": "out"
}

Custom output path:

config:
templates:
text: "Hello {{payload.name}}"
output_path: "reply.body"
{
"payload": {
"reply": {
"body": "Hello Ada"
}
},
"routing": "out"
}

Raw string output:

config:
templates:
text: "Hello {{payload.name}}"
wrap: false
{
"payload": "Hello Ada",
"routing": "out"
}

Start from the wizard instead of copying this component by hand:

Terminal window
greentic-component wizard --schema
greentic-component wizard --answers component-template-answers.json

For a pack-owned component, use the top-level launcher:

Terminal window
gtc wizard --schema
gtc wizard --answers pack-with-template-component.answers.json

Set operation_names to the operations you need, for example render_text,render_email. Turn on advanced_setup when the component needs HTTP, state, secrets, events, messaging, filesystem access, or custom config fields. The wizard writes the manifest, WIT bindings, QA scaffolding, i18n keys, build/test wiring, and default operation metadata.