Handlebars Templates for Document Generation
A Handlebars template is a Word document or Google Doc that contains placeholders (written as double curly braces around a variable name like {{VariableName}}) which the platform substitutes with real data to produce a finished document. The syntax follows the Handlebars.js open-source templating specification and the platform uses the jsreport docx engine.
Templates are the main way to generate formatted outputs like employment letters, purchase order confirmations, and exception notifications. The template defines the structure and formatting; the workflow step supplies the data.
Template Syntax
Variable Substitution
A placeholder is written as {{VariableName}} and placed anywhere in the document body, table cells, headings, or footers. When the workflow runs, the platform replaces each placeholder with the matching data value.
Employment Verification LetterEmployee: {{EmployeeName}}
Job Title: {{JobTitle}}
Start Date: {{StartDate}}
Contract: {{ContractType}}
Location: {{WorkLocation}}{{Purpose}}
Conditional Blocks
{{#if VariableName}} renders a block only when the value is truthy.
{{#if SalaryIncluded}}
Compensation: {{CompensationBase}}
{{/if}}
If SalaryIncluded has no value (is empty or false), the block is omitted.
Loops
{{#each List}} repeats a block once for each item in an array.
{{#each OrderItems}}
- {{this.Description}}: {{this.Quantity}} units
{{/each}}
Unescaped HTML
Triple braces {{{VariableName}}} insert the value as raw HTML rather than escaped text. This is appropriate when the value contains HTML markup.
The use_as_template Tool
The use_as_template tool generates a populated document from a template file. It is available in any thunk with the DocumentTemplates module enabled. The tool must be enabled at the thunk level and at each step that generates a document (see your thunk settings).
The step identifies the template file by its SharePoint, OneDrive, or Google Drive URL and specifies which workflow properties map to each placeholder. The result is a populated document saved as a new file.
Writing Step Guidance
When use_as_template is enabled for a step, the agent automatically selects it when the step guidance describes generating a document from a template. The step guidance should specify the template file URL, the fields to populate, and the output filename.
Typical instructions might read:
Open TemplateName.docx and generate a new document named "Letter - {{EmployeeName}} - {{Date}}.docx". Populate it with EmployeeName, JobTitle, StartDate, ContractType, WorkLocation, and Purpose. If SalaryIncluded is Y, also include CompensationBase.
The agent resolves placeholder values from workflow properties and calls the tool.
Tip: The AI agent will do its best to match placeholder names to available data. Aligned placeholder names between the document template and the Thunk properties, or explicit per-field instructions on the mappings, in the step guidance produce the most reliable results.
Examples in the Sample Library
The following samples use use_as_template to generate documents from stored template files.
Process HR Employee Letter Requests: selects a template based on letter type and country, then populates it with verified employee data including conditional salary disclosure.
Process Incoming Purchase Orders: generates a fulfillment notification from a stored template once payment terms are confirmed, populated with order and delivery details.
Syntax Reference
This is a partial list of commonly used helpers. Refer to the jsreport docx engine for the full reference.
Syntax | Purpose |
| Insert a value |
| Insert raw HTML (unescaped) |
| Render block only when value is truthy |
| Repeat block for each item in an array |
| Reference a property within an |
| Generate a Word list from an array |
| Generate a Word table from an array |
| Apply dynamic text or background color to a block |
| Insert a dynamic image (link via Word bookmark) |
| Embed HTML as formatted Word content (paragraphs, lists, tables, etc.) |
| Insert a page break |
| Conditionally remove a paragraph, row, or table |
