Template Variables - Dynamic Workflow Magic
Template variables make your workflows dynamic and intelligent by allowing you to reference data from anywhere in your workflow. Using the {{variable}}
syntax, you can create powerful, reusable workflows that adapt to different inputs and conditions.
🌟 Overview
Template variables are placeholders that get replaced with actual values during workflow execution. Think of them as dynamic references that make your workflows smart and flexible.
Why Use Template Variables?
- Dynamic Content: Reference data from previous nodes
- Reusable Workflows: Build once, use with different inputs
- Smart Routing: Make decisions based on runtime data
- Configuration Management: Use environment variables and settings
- Data Transformation: Combine and manipulate values on the fly
📝 Basic Syntax
Simple Variable
{{variableName}}
Nested Properties
{{user.profile.email}}
{{order.items[0].name}}
{{response.data.results}}
With Fallback (Coming Soon)
{{user.name || 'Guest'}}
{{config.timeout || 5000}}
🎯 Variable Sources
1. Input Data
Reference the current node's input:
{{input}} // Entire input object
{{input.message}} // Specific field
{{input.users[0]}} // Array element
Example in Agent Node Prompt:
Summarize this article: {{input.articleText}}
The user {{input.userName}} wants a summary in {{input.language}}.
2. Previous Node Output
Reference any previous node by name:
{{nodes.nodeName.output}}
{{nodes.agent1.result}}
{{nodes.api_call.response.data}}
Example Workflow:
- API Node (name: "fetch_user") → Fetches user data
- Agent Node → Prompt:
Analyze user {{nodes.fetch_user.output.name}}
- Action Node → Send email to
{{nodes.fetch_user.output.email}}
3. Workflow Context
Access workflow-level information:
{{workflow.id}}
{{workflow.name}}
{{workflow.executionId}}
{{workflow.startTime}}
4. Environment Variables
Reference configuration and secrets:
{{env.API_KEY}}
{{env.DATABASE_URL}}
{{env.WEBHOOK_SECRET}}
5. System Variables
Built-in system values:
{{timestamp}} // Current timestamp
{{date}} // Current date
{{random}} // Random value
{{uuid}} // Unique identifier
💡 Where to Use Template Variables
Agent Node Prompts
Create dynamic AI prompts:
You are a {{input.role}} assistant helping {{input.userName}}.
Previous context: {{nodes.previous_chat.output}}
User's question: {{input.question}}
Please provide a {{input.responseStyle}} response.
Action Node Configuration
Dynamic HTTP requests:
URL:
https://api.example.com/users/{{input.userId}}/orders
Headers:
{
"Authorization": "Bearer {{env.API_TOKEN}}",
"X-User-ID": "{{input.userId}}",
"X-Session": "{{workflow.executionId}}"
}
Body:
{
"orderId": "{{nodes.create_order.output.id}}",
"status": "{{input.orderStatus}}",
"timestamp": "{{timestamp}}"
}
Condition Node
Dynamic conditions:
Field: {{input.user.accountType}}
Operator: equals
Value: premium
Or reference previous calculations:
Field: {{nodes.calculate_total.output.amount}}
Operator: greater than
Value: 1000
Loop Node
Dynamic iteration:
Array Path: {{input.items}}
Max Iterations: {{config.batchSize}}
Inside the loop:
{{item}}
- Current item{{index}}
- Current index{{items}}
- Full array
Plugin Nodes
Configure plugin actions dynamically:
Slack Plugin:
{
"channel": "{{input.slackChannel}}",
"message": "Order {{nodes.order.output.id}} processed",
"user": "{{nodes.customer.output.slackId}}"
}
Email Plugin:
{
"to": "{{input.email}}",
"subject": "Welcome {{input.firstName}}!",
"body": "{{nodes.generate_email.output}}"
}
🚀 Advanced Usage
Chaining Variables
Build complex references:
{{nodes.api_call.output.users[0].profile.email}}
{{input.data[{{input.selectedIndex}}].value}}
In Code Nodes
Template variables work in Code nodes too:
// Template variables are replaced before execution
const apiKey = "{{env.API_KEY}}";
const userName = "{{input.user.name}}";
const previousResult = {{nodes.processor.output.total}};
// Use them in your JavaScript
if (previousResult > 100) {
return {
alert: true,
message: `High value order for ${userName}`
};
}
Conditional Templates
Use in condition logic:
// In a Condition node
Field: {{input.country}}
Value: {{env.HOME_COUNTRY}}
// Routes differently based on environment config
Dynamic Node Names
Reference nodes dynamically (advanced):
{{nodes[input.selectedNode].output}}
📚 Common Patterns
1. Data Enrichment Pipeline
Node 1 (fetch_user): API call to get user
Node 2 (enrich):
Prompt: "Analyze {{nodes.fetch_user.output.profile}}"
Node 3 (update):
API call with body: {
"id": "{{nodes.fetch_user.output.id}}",
"analysis": "{{nodes.enrich.output}}"
}
2. Multi-Step Form Processing
Node 1: Receive form data
Node 2: Validate with prompt:
"Check if {{input.email}} is valid and {{input.age}} is over 18"
Node 3: Condition on {{nodes.validator.output.isValid}}
Node 4a: If valid - process with {{input}} data
Node 4b: If invalid - return errors {{nodes.validator.output.errors}}
3. Dynamic Routing
Node 1: Categorize with AI:
"What category is this: {{input.text}}"
Node 2: Condition node checking {{nodes.categorizer.output.category}}
- Route to different branches based on category
4. Iterative Processing
Loop Node:
Array: {{input.items}}
Inside loop:
Agent: "Process item: {{item.name}} with price {{item.price}}"
Action: Update database with {{item.id}} and {{nodes.agent.output}}
🔧 Debugging Template Variables
Check Variable Values
- Use Code Node for debugging:
console.log('Input:', {{input}});
console.log('Previous node:', {{nodes.previousNode.output}});
return {
debug: {
input: {{input}},
previous: {{nodes.previousNode.output}}
}
};
- Test with sample data:
- Run partial workflows
- Use test inputs
- Check node outputs
Common Issues and Solutions
Issue: Variable not replaced
- Check variable name spelling
- Ensure node has executed
- Verify path to nested properties
Issue: Undefined or null
- Add fallback values
- Check if previous node produced output
- Validate data structure
Issue: Wrong data type
- Use Code node to convert types
- Ensure JSON formatting
- Check array vs object access
🎨 Real-World Examples
Customer Support Automation
Trigger: Support ticket webhook
Node 1 - Extract Info:
Code: Extract key fields from {{input.ticket}}
Node 2 - Analyze Sentiment:
Agent: "What's the sentiment of: {{nodes.extract.output.message}}"
Node 3 - Generate Response:
Agent: "Draft a {{nodes.sentiment.output.tone}} response to: {{input.ticket.issue}}"
Node 4 - Send Response:
Email to: {{input.ticket.customerEmail}}
Body: {{nodes.response_generator.output}}
Dynamic Pricing Calculator
Input: Product details and customer info
Node 1 - Get Base Price:
API: /products/{{input.productId}}
Node 2 - Calculate Discount:
Code: Apply discount based on {{input.customer.tier}}
Node 3 - Add Shipping:
Code: Calculate shipping for {{input.address.country}}
Node 4 - Final Price:
Return: {
base: {{nodes.base_price.output.price}},
discount: {{nodes.discount.output.amount}},
shipping: {{nodes.shipping.output.cost}},
total: {{nodes.calculate_total.output}}
}
Content Generation Pipeline
Input: Topic and style preferences
Node 1 - Research:
Agent: "Research facts about {{input.topic}}"
Node 2 - Outline:
Agent: "Create outline using: {{nodes.research.output}}"
Node 3 - Write Sections:
Loop through {{nodes.outline.output.sections}}
Agent: "Write about {{item}} in {{input.style}} style"
Node 4 - Combine:
Code: Combine all sections with title {{input.title}}
Node 5 - Format:
Agent: "Format for {{input.platform}}: {{nodes.combine.output}}"
🚦 Best Practices
1. Use Descriptive Node Names
// Good ✅
{{nodes.fetch_customer_data.output}}
{{nodes.calculate_tax.output.total}}
// Bad ❌
{{nodes.node1.output}}
{{nodes.a.output.x}}
2. Handle Missing Data
// In Code node
const userName = "{{input.user.name}}" || "Guest";
const items = {{input.items}} || [];
3. Document Variable Usage
Add comments in prompts:
Process order for {{input.customerName}} // Customer from form input
Using shipping address: {{nodes.address_lookup.output}} // From previous API call
4. Test with Various Inputs
- Empty strings
- Missing properties
- Different data types
- Edge cases
5. Use Environment Variables for Config
API Endpoint: {{env.API_BASE_URL}}/users
Timeout: {{env.DEFAULT_TIMEOUT}}
Mode: {{env.ENVIRONMENT}}
🔮 Future Features
Coming soon:
- Filters:
{{input.name | uppercase}}
- Fallbacks:
{{input.value || 'default'}}
- Expressions:
{{input.price * 1.2}}
- Conditionals:
{{input.isPremium ? 'VIP' : 'Standard'}}
📖 Related Documentation
- Code Node Guide - Using variables in custom JavaScript
- Workflow Building - Understanding data flow
- Node Reference - How each node uses variables
- Debugging Guide - Troubleshooting variable issues