Template Expressions
Loopstack uses Handlebars templates for rendering dynamic text content. Templates are rendered via this.render() in workflow methods.
Usage
const rendered = this.render(__dirname + '/templates/prompt.md', {
subject: args.subject,
items: this.items,
});Template file (templates/prompt.md):
Write a haiku about {{subject}}.
{{#each items}}
- {{this.name}}
{{/each}}Passing Data
Pass any data as the second argument to this.render():
// Workflow args
const args = this.ctx.args as { subject: string };
this.render(templatePath, { subject: args.subject });
// Workflow state
this.render(templatePath, { items: this.items, count: this.counter });
// Mixed data
this.render(templatePath, {
prompt: args.prompt,
history: this.conversationHistory,
timestamp: new Date().toISOString(),
});Handlebars Syntax
Variables
Hello {{name}}
Nested: {{user.profile.email}}
Array element: {{items.[0]}}Conditionals
{{#if isActive}}Welcome back!{{else}}Please log in{{/if}}
{{#unless isBlocked}}Access granted{{/unless}}Iteration
{{#each items}}
- {{this.name}}: {{this.value}}
{{else}}
No items found.
{{/each}}Context Scoping
{{#with user}}{{name}} ({{email}}){{/with}}Multi-line Template Example
# Events This Week
{{#each events}}
- **{{this.summary}}**: {{this.start}} – {{this.end}}
{{/each}}
{{#unless events}}
No events found.
{{/unless}}When to Use Templates
| Scenario | Approach |
|---|---|
| LLM prompts with variables | this.render(templatePath, data) |
| Simple string interpolation | Template literals in TypeScript |
| Complex multi-line content | Handlebars template file |
| Prompts with iteration/conditionals | Handlebars with #each, #if |
YAML UI Config
YAML widget configuration uses transition values that reference method names and enabledWhen for conditional visibility. These are not template expressions — they are static configuration:
ui:
widgets:
- widget: prompt-input
enabledWhen: [waiting_for_user]
options:
transition: userMessageRegistry References
- prompt-example-workflow — Uses
this.render()for Handlebars prompt templates - meeting-notes-example-workflow — Uses templates for structured note rendering
Last updated on