Overview
The DocumentGenerator node renders data using a Handlebars template. It allows you to generate custom text outputs by merging input data with either a provided template string or a template fetched from a URL. This is useful for generating dynamic documents, emails, reports, or any text-based content where the structure is defined by a template and the content comes from your workflow data.
Common scenarios:
- Generating personalized email bodies for each contact in a list.
- Creating formatted reports from tabular data.
- Producing templated notifications or messages based on incoming data.
Practical example:
Suppose you have a list of users and want to send each a customized welcome message. You can use this node to merge user data into a Handlebars template, producing a unique message for each user.
Properties
Below are the supported input properties:
| Display Name | Type | Meaning |
|---|---|---|
| Template String | string | The Handlebars template as a direct string. Used when "Use a Template String" is enabled. |
| Template URL | string | The URL to fetch the Handlebars template from. Used when "Use a Template String" is disabled. |
| Output Key | string | The property name under which the rendered text will be saved in the output. Only shown if "Define a Custom Output Key" is set. |
Note:
- Only one of "Template String" or "Template URL" is required, depending on the "Use a Template String" toggle.
- "Output Key" is only required if "Define a Custom Output Key" is enabled; otherwise, the default key is
text.
Output
The node outputs an array of items, each containing a json object with the rendered result.
Structure:
[
{
"json": {
"text": "<rendered output here>"
}
}
]
- If a custom output key is specified,
"text"will be replaced by your chosen key. - When rendering all items with one template (using the "Render All Items with One Template" option), the output will contain a single item with the rendered result.
- No binary data is produced by this node.
Dependencies
- External Library: Uses @jaredwray/fumanchu for Handlebars template rendering.
- Template URL: If using a template URL, the node requires network access to fetch the template.
- No credentials or API keys are required unless your template URL is protected.
Troubleshooting
Common issues:
- Invalid Handlebars syntax: If your template contains errors, rendering will fail. Double-check your template against the Handlebars documentation.
- Missing required fields: Ensure that all required properties ("Template String" or "Template URL", and "Output Key" if custom key is enabled) are filled.
- Network errors: If fetching a template from a URL fails, check the URL and your network connection.
- Empty output: If the output is empty, verify that your input data matches the variables used in your template.
Error messages you might see:
- "Cannot read property 'compile' of undefined" — Indicates an issue with the Handlebars library or template loading.
- "Request failed with status code XXX" — Problem fetching the template from the provided URL.