Template
Renders a Handlebars template string with dynamic values from a context object.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
info
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- Template - A Handlebars template string with placeholders (e.g.,
"Hello {{name}}"). - Context - An object containing the values to insert into the template.
Options
This node does not have configurable options.
Output
- Rendered - The template with all placeholders replaced by values from the context object.
How It Works
The Template node uses Handlebars templating engine to render dynamic strings:
- Takes a template string with placeholders in
{{variable}}format - Takes a context object with values
- Replaces each
{{placeholder}}with the corresponding value from context - Returns the rendered string
Handlebars Features:
- Simple variable substitution:
{{name}} - Nested properties:
{{user.email}} - Array access:
{{items.[0]}} - Conditionals:
{{#if condition}}...{{/if}} - Loops:
{{#each items}}...{{/each}} - Helpers:
{{uppercase name}}
Usage Examples
Example 1: Simple Variable Substitution
- Template:
"Hello {{name}}!" - Context:
{name: "John"} - Rendered:
"Hello John!"
Example 2: Multiple Variables
- Template:
"{{firstName}} {{lastName}} lives in {{city}}" - Context:
{firstName: "John", lastName: "Doe", city: "New York"} - Rendered:
"John Doe lives in New York"
Example 3: Nested Properties
- Template:
"Email: {{user.email}}, Phone: {{user.phone}}" - Context:
{user: {email: "john@example.com", phone: "555-1234"}} - Rendered:
"Email: john@example.com, Phone: 555-1234"
Example 4: Conditional Content
- Template:
"Status: {{#if active}}Active{{else}}Inactive{{/if}}" - Context:
{active: true} - Rendered:
"Status: Active"
Example 5: Loop Through Array
- Template:
"Items: {{#each items}}{{this}}, {{/each}}" - Context:
{items: ["Apple", "Banana", "Orange"]} - Rendered:
"Items: Apple, Banana, Orange, "
Tips
- Use for email templates with dynamic content
- Perfect for generating reports with variable data
- Great for building dynamic messages
- Use for URL construction with parameters
- Supports nested objects and arrays
- Escape HTML automatically in Handlebars (use triple braces
{{{raw}}}for unescaped) - More powerful than simple concatenation for complex strings
Common Errors and Solutions
Error: Variable not found in context
- Cause: Template references
{{name}}but context doesn't havenameproperty - Solution: Ensure all template variables exist in context object
Error: Syntax error in template
- Cause: Invalid Handlebars syntax
- Solution: Check for matching
{{#if}}with{{/if}}, proper helper syntax
Error: Nested property returns undefined
- Cause:
{{user.email}}butuseris undefined - Solution: Ensure nested objects exist or use conditionals
Practical RPA Examples
Example: Email Template
Template:
"Dear {{customerName}},
Your order #{{orderId}} has been {{status}}.
Total: ${{amount}}
Thank you for your business!"
Context:
{
customerName: "John Doe",
orderId: "12345",
status: "shipped",
amount: "99.99"
}
Rendered:
"Dear John Doe,
Your order #12345 has been shipped.
Total: $99.99
Thank you for your business!"
Example: Generate Report
Template:
"Sales Report for {{month}}
Total Sales: ${{totalSales}}
Orders: {{orderCount}}
Average: ${{avgOrderValue}}"
Context:
{
month: "January 2024",
totalSales: "50000",
orderCount: "150",
avgOrderValue: "333.33"
}
Example: Build API URL
Template: "https://api.example.com/v1/users/{{userId}}/orders/{{orderId}}"
Context: {userId: "123", orderId: "456"}
Rendered: "https://api.example.com/v1/users/123/orders/456"
Example: Dynamic SQL Query
Template: "SELECT * FROM {{table}} WHERE {{field}} = '{{value}}'"
Context: {table: "customers", field: "email", value: "john@example.com"}
Rendered: "SELECT * FROM customers WHERE email = 'john@example.com'"
warning
Always validate and sanitize inputs when building SQL queries to prevent SQL injection.
Example: Generate Filename
Template: "{{prefix}}_{{date}}_{{id}}.{{extension}}"
Context: {
prefix: "report",
date: "2024-01-15",
id: "12345",
extension: "pdf"
}
Rendered: "report_2024-01-15_12345.pdf"
Handlebars Features
Simple Variables
Template: "Hello {{name}}"
Context: {name: "World"}
Result: "Hello World"
Nested Objects
Template: "{{person.firstName}} {{person.lastName}}"
Context: {person: {firstName: "John", lastName: "Doe"}}
Result: "John Doe"
Conditionals
Template: "{{#if isPremium}}Premium User{{else}}Regular User{{/if}}"
Context: {isPremium: true}
Result: "Premium User"
Loops (Each)
Template: "{{#each items}}Item: {{this}}\n{{/each}}"
Context: {items: ["A", "B", "C"]}
Result: "Item: A\nItem: B\nItem: C\n"
Loops with Index
Template: "{{#each items}}{{@index}}: {{this}}\n{{/each}}"
Context: {items: ["A", "B", "C"]}
Result: "0: A\n1: B\n2: C\n"
Array of Objects
Template: "{{#each users}}Name: {{name}}, Age: {{age}}\n{{/each}}"
Context: {users: [{name: "John", age: 30}, {name: "Jane", age: 25}]}
Result: "Name: John, Age: 30\nName: Jane, Age: 25\n"
Advanced Examples
Example: Invoice Template
Template:
"INVOICE #{{invoiceNumber}}
Date: {{date}}
Customer: {{customer.name}}
Address: {{customer.address}}
Items:
{{#each items}}
- {{name}}: ${{price}} x {{quantity}} = ${{total}}
{{/each}}
Subtotal: ${{subtotal}}
Tax: ${{tax}}
Total: ${{total}}"
Context: {
invoiceNumber: "INV-2024-001",
date: "2024-01-15",
customer: {
name: "John Doe",
address: "123 Main St"
},
items: [
{name: "Widget", price: "10.00", quantity: 2, total: "20.00"},
{name: "Gadget", price: "15.00", quantity: 1, total: "15.00"}
],
subtotal: "35.00",
tax: "3.50",
total: "38.50"
}
Example: HTML Email
Template:
"<html>
<body>
<h1>Welcome {{userName}}!</h1>
<p>Thank you for signing up.</p>
{{#if verified}}
<p>Your email is verified.</p>
{{else}}
<p>Please verify your email.</p>
{{/if}}
</body>
</html>"
Context: {
userName: "John",
verified: false
}
Example: Dynamic Configuration
Template:
"server: {{server.host}}:{{server.port}}
database: {{db.name}}
enabled: {{features.enabled}}"
Context: {
server: {host: "localhost", port: 8080},
db: {name: "production"},
features: {enabled: true}
}
Pattern: Multi-Language Templates
Create localized messages:
English Template: "Hello {{name}}, you have {{count}} new messages"
Spanish Template: "Hola {{name}}, tienes {{count}} mensajes nuevos"
Context: {name: "Juan", count: 5}
Pattern: Dynamic Form Generation
Generate form HTML:
Template:
"{{#each fields}}
<div>
<label>{{label}}</label>
<input type='{{type}}' name='{{name}}'>
</div>
{{/each}}"
Context: {
fields: [
{label: "Name", type: "text", name: "userName"},
{label: "Email", type: "email", name: "userEmail"}
]
}
Error Handling
Missing Variable
Template: "Hello {{name}}"
Context: {}
Result: "Hello " (empty value)
Missing Nested Property
Template: "{{user.email}}"
Context: {user: null}
Result: "" or error depending on strictness
Invalid Syntax
Template: "{{#if condition}}" (missing closing tag)
Result: Template parsing error
Best Practices
- Validate Context - Ensure all required variables exist
- Use Conditionals - Check for optional fields with
{{#if}} - Escape Data - Be careful with user input in HTML templates
- Test Templates - Verify output with sample data
- Keep It Simple - Complex logic belongs in code, not templates
- Document Variables - List all required context properties
Related Nodes
- Concatenate - Simple string joining
- Join - Join array with separator
- Replace - Simple find and replace
- ToString - Convert values to string before templating