Skip to main content

Template Transformation

The template node is used to dynamically format and combine variables from preceding nodes to generate structured text output. It supports Handlebars template syntax, making it ideal for integrating multiple data sources into a text structure suitable for subsequent node processing.

This approach is particularly useful for:

  • Combining multiple fields into natural language, Markdown, HTML, or other formats
  • Constructing dynamic tables or list content
  • Generating intermediate prompt information before AI responses

๐Ÿ”ง Usage Example: Concatenating Article Contentโ€‹

# {{ title }}

> Author: {{ author }}
> Date: {{ date }}

## Summary

{{ summary }}

## Body

{{#each sections}}
### {{ this.heading }}

{{ this.content }}

---
{{/each}}

This template takes data from upstream nodes, such as article title, author, date, and section content, and outputs a structured Markdown document.

๐Ÿ“ฆ Input Example:

{
"title": "How to Build an AI Copilot",
"author": "XpertAI",
"date": "2025-05-29",
"summary": "This article introduces how to build AI assistants tailored for business scenarios in enterprise systems.",
"sections": [
{ "heading": "Background", "content": "The demand for intelligent analysis in enterprises is growing..." },
{ "heading": "Implementation", "content": "Combine LLMs, workflow orchestration, and data indexing..." }
]
}
Template transform
Template Transformation

Input Parameters

  • Variable Name: Uses the value of this state variable in the template context.
  • Empty Variable Name: Uses this variable value as the global template context.

๐Ÿ’ก Advanced Usageโ€‹

Conditional Logic:โ€‹

{{#if user.vip}}
Welcome, esteemed VIP user {{ user.name }}!
{{else}}
Welcome, {{ user.name }}!
{{/if}}

Looping Lists:โ€‹

{{#each items}}
- {{ this }}
{{/each}}

Table Construction:โ€‹

| Metric | Value |
|--------|-------|
{{#each metrics}}
| {{ name }} | {{ value }} |
{{/each}}

๐Ÿง  Application Scenariosโ€‹

  • Knowledge Retrieval Formatting: Unify content blocks from document retrieval
  • Markdown Message Output: Prepare structured responses for platforms like Feishu or Slack
  • Form Construction: Output interactive HTML form content
  • Pre-AI Response Guidance: Generate intermediate prompts to guide further user interaction

๐Ÿงช Example: Output HTML Formโ€‹

<form>
<label for="username">Username:</label>
<input type="text" name="username" />

<label for="email">Email:</label>
<input type="email" name="email" />

<button>Submit</button>
</form>

This HTML can be dynamically generated by the template node and displayed on downstream platforms, supporting custom fields and prompt information.


๐Ÿ“Œ Tipsโ€‹

  • Variables in the template come from the JSON output of upstream nodes.
  • Supports nested access, e.g., user.name, item.metadata.score.

The template node is typically used in the middle of a workflow to format output results for display or to pass to the next tool node or model call.

For detailed Handlebars syntax, refer to the Handlebars Official Documentation.