Render Template
使用 Handlebars 模板引擎生成动态文本。
使用输入 payload 渲染 Handlebars 模板,并将结果文本以 text 添加到 payload。
该算子将数据变量合并到文本模板中,非常适合构建邮件、短信、HTML 文档或 SQL 查询。
功能特性:
- Handlebars 语法: 使用
{{variable}}、{{#each list}}、{{#if condition}}。 - 丰富的输入: 可将整个载荷作为上下文完整访问。
适用场景:
- 生成个性化邮件正文:“Hello {{user.name}}...”
- 构建复杂的文件路径:“/archives/{{year}}/{{month}}/report.pdf”
工作原理
- 从配置中原样读取
template:它不经过 Expression Engine,因此其中所有{{ }}都属于 Handlebars。其他配置键照常解析。 - 用 Handlebars 4 编译,并以 payload 为上下文渲染:
{{customer.name}}、{{#each items}}...{{/each}}、{{#if paid}}...{{/if}}。 - 通过
out返回 payload 加上text。
在工作流中
节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。
{
"node_id": "node-ready-message",
"label": "Ready message",
"operator_slug": "data.template",
"operator_version": "1.0.0",
"config": {
"template": "Hello {{customer.name}}, your order {{order_id}} is ready."
}
}{
"ok": true,
"data": {
"customer": {
"name": "Ana"
},
"order_id": "ord_123",
"text": "Hello Ana, your order ord_123 is ready."
},
"port": "out"
}配置
-
templatestring 必填 -
使用 Handlebars 语法的文本模板。
配置中会显示通用执行设置,但该节点目前不执行重试(retryOnFail、maxTries)。所有节点均未实现 continueOnFail。
代码中的行为
除 schema 描述之外,实现代码对这些键的实际处理。
-
template - 只能访问 payload 字段。Expression Engine 变量(
$json、$("Node")、$now、$execution)在此不可用:请写{{order_id}},而不是{{ $json.order_id }}。空模板渲染为""。
输出端口
out 默认 模板渲染完成。
{
"customer": {
"name": "Ana"
},
"order_id": "ord_123",
"text": "Hello Ana, your order ord_123 is ready."
}error 模板存在语法错误。
{
"ok": false,
"errors": [
"Template Error: Parse error on line 1: ..."
],
"port": "error"
}在表达式中
后续节点可通过 $("Render Template").item.json.<路径> 读取此节点输出中的内容(请把 Render Template 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 out 返回的路径,依据“端口”一节所示的输出。
| 表达式 | Editor | Worker |
|---|---|---|
$("Render Template").item.json.result渲染后的字符串。 | — | |
$("Render Template").item.json.customer | — | |
$("Render Template").item.json.customer.name | — | |
$("Render Template").item.json.order_id | — | |
$("Render Template").item.json.text | — |
— Editor: 编辑器会提示它,但 worker 并不返回:读取结果为 undefined。
— Worker: worker 会返回它,但编辑器不会提示:请手动输入。对象内部的键可能取决于你的数据或配置(例如每个标签一个键)。
错误
| 消息 | 端口 | 原因与处理 |
|---|---|---|
Template Error: Parse error on line <n>: <details> | error | Handlebars 语法无效,例如 {{#if}} 块未闭合。 |
输入契约
-
payloadobject 可选 -
模板中可用的数据上下文。
输出契约
-
resultstring 可选 -
渲染后的字符串。
契约(JSON Schema)
与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。
{
"slug": "data.template",
"name": "Render Template",
"category": "data",
"version": "1.0.0",
"description": "Generates dynamic text using the Handlebars templating engine.\n\n This operator allows you to merge data variables into a text template. It is ideal for constructing emails, SMS messages, HTML documents, or SQL queries.\n\n **Features:**\n - **Handlebars Syntax:** usage of `{{variable}}`, `{{#each list}}`, `{{#if condition}}`.\n - **Rich Input:** Full access to the payload as context.\n\n **Use Cases:**\n - Creating a personalized email body: \"Hello {{user.name}}...\"\n - Constructing a complex file path: \"/archives/{{year}}/{{month}}/report.pdf\"",
"capabilities": [
"templating",
"handlebars",
"text-generation"
],
"config_schema": {
"type": "object",
"required": [
"template"
],
"properties": {
"template": {
"type": "string",
"title": "Template String",
"format": "textarea",
"description": "The text template using Handlebars syntax."
},
"execution": {
"type": "object",
"title": "Execution Settings",
"properties": {
"alwaysOutputData": {
"type": "boolean",
"title": "Always Output Data",
"description": "Always output data, even on error (if configured).",
"default": false
},
"retryOnFail": {
"type": "boolean",
"title": "Retry On Fail",
"description": "Retry the execution if it fails.",
"default": false
},
"maxTries": {
"type": "integer",
"title": "Max Retries",
"description": "Number of retries.",
"default": 3,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"waitBetweenTries": {
"type": "integer",
"title": "Wait Between Retries (ms)",
"default": 1000,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"continueOnFail": {
"type": "boolean",
"title": "Continue On Fail",
"description": "Do not crash workflow on error.",
"default": false
},
"timeout_ms": {
"type": "integer",
"title": "Timeout (ms)",
"description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
"default": 300000
}
}
}
}
},
"input_contract_schema": {
"type": "object",
"properties": {
"payload": {
"type": "object",
"description": "Data context available in the template."
}
}
},
"output_contract_schema": {
"type": "object",
"properties": {
"result": {
"type": "string",
"description": "The rendered string."
}
}
},
"ports": [
{
"port_id": "out",
"label": "Rendered",
"is_default": true
},
{
"port_id": "error",
"label": "Error"
}
],
"execution_mode": "sync",
"tags": [
"handlebars",
"html",
"template",
"text"
],
"is_stateful": false,
"publisher": {
"identity": "org_link_loom",
"profile": {
"name": "Link Loom",
"verified": true,
"url": "https://me.veripass.com/link-loom",
"logo_url": null
}
}
}{
"type": "object",
"required": [
"template"
],
"properties": {
"template": {
"type": "string",
"title": "Template String",
"format": "textarea",
"description": "The text template using Handlebars syntax."
},
"execution": {
"type": "object",
"title": "Execution Settings",
"properties": {
"alwaysOutputData": {
"type": "boolean",
"title": "Always Output Data",
"description": "Always output data, even on error (if configured).",
"default": false
},
"retryOnFail": {
"type": "boolean",
"title": "Retry On Fail",
"description": "Retry the execution if it fails.",
"default": false
},
"maxTries": {
"type": "integer",
"title": "Max Retries",
"description": "Number of retries.",
"default": 3,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"waitBetweenTries": {
"type": "integer",
"title": "Wait Between Retries (ms)",
"default": 1000,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"continueOnFail": {
"type": "boolean",
"title": "Continue On Fail",
"description": "Do not crash workflow on error.",
"default": false
},
"timeout_ms": {
"type": "integer",
"title": "Timeout (ms)",
"description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
"default": 300000
}
}
}
}
}{
"type": "object",
"properties": {
"payload": {
"type": "object",
"description": "Data context available in the template."
}
}
}{
"type": "object",
"properties": {
"result": {
"type": "string",
"description": "The rendered string."
}
}
}[
{
"port_id": "out",
"label": "Rendered",
"is_default": true
},
{
"port_id": "error",
"label": "Error"
}
]执行
- 执行方式
sync- 有状态
- 否
- 重试(
retryOnFail) - 否
- 能力
templatinghandlebarstext-generation- 标签
handlebarshtmltemplatetext
说明与限制
{{ }}会转义 HTML 字符(&、<、>、引号);需要原样输出时请用{{{ }}}。- 只提供 Handlebars 内置 helper(
if、unless、each、with、lookup、log);未注册自定义 helper。缺失字段渲染为空文本。 - 输出键为
text(输出契约写的是result);已有的text键会被覆盖。 - 当返回的信封没有
data(或data为假值)时,引擎会把整个信封作为节点输出:经error端口时,下一个节点收到的 payload 是{ ok: false, errors: [...], port: "error" }。
已对照编排器代码核实 · 31e874b · 2026-11-26