Templates and Data Binding
Overview
Build a Doc uses a template-driven approach to document generation. Templates define the structure and layout of your documents, while data binding connects your data sources to placeholders within the template.
What is a Template?
A template is a document that serves as a blueprint for your generated output. It contains:
- Static Content - Text, images, tables, and formatting that remain unchanged
- Template Expressions - Placeholders that are replaced with data at runtime
- Control Logic - Conditionals and loops that control document flow
Supported Template Types
| Template Type | File Formats | Template Syntax |
|---|---|---|
| Word | .doc, .docx | <<[expression]>> |
| Excel | .xls, .xlsx | <<[expression]>> |
| HTML | .html | {{expression}} |
For additional information on template syntax, see the relevant template-language guides:
Data Binding Fundamentals
Data binding is the process of connecting template expressions to values in your data source.
Basic Binding
The simplest binding references a property directly:
Data Source:
[ { "Name": "Customer", "Data": { "CustomerName": "John Smith" } }]Template:
Customer: <<[CustomerName]>>Output:
Customer: John SmithNested Property Binding
Access properties within objects using dot notation:
Data Source:
[ { "Name": "Customer", "Data": { "Name": "John Smith", "Address": { "City": "London" } } }]Template:
<<[Customer.Name]>> lives in <<[Customer.Address.City]>>Output:
John Smith lives in LondonData Source Naming
When calling a Build a Doc action, you specify:
- Data source Name - The identifier used in templates
- Data source Data - The actual data
- Data source Format - JSON, XML, or CSV
For detailed guidance on formatting your JSON data correctly, see Structure JSON Data.
The Name becomes the root accessor in your template:
Action Configuration:
Name: InvoiceData: { "Number": "INV-001", "Total": 500 }Template Access:
Invoice #<<[Invoice.Number]>> - Total: £<<[Invoice.Total]>>Multiple Data Sources
You can provide multiple data sources to a single action:
| Name | Data |
|---|---|
| Company | { "Name": "Acme Ltd" } |
| Invoice | { "Number": "001", "Items": [...] } |
| Metadata | { "GeneratedDate": "2025-01-22" } |
Template:
<<[Company.Name]>>Invoice: <<[Invoice.Number]>>Generated: <<[Metadata.GeneratedDate]>>Array Binding
Bind to arrays using loops:
Data Source:
[ { "Name": "Catalogue", "Data": { "Products": [ { "Name": "Widget A", "Price": 10.0 }, { "Name": "Widget B", "Price": 15.0 } ] } }]Template:
<<foreach [product in Catalogue]>>- <<[product.Name]>>: £<<[product.Price]>><</foreach>>Output:
- Widget A: £10.00- Widget B: £15.00Null and Missing Values
When a referenced property doesn’t exist or is null:
- Default behaviour - Missing or null values evaluate to
null/undefined;ifblocks that reference them will not render and standalone placeholders produce no output. - With Error Display - When inline error display is enabled, template errors are shown in the output document to help debugging.
For handling optional data, use conditionals and null-coalescing operators: