Skip to Content
DocumentationWorking with YAML SchemasExpressionsHandlebars Expressions {{ }}

Handlebars Expressions {{ }}

Loopstack uses Handlebars  for rendering Template Expressions. Template expressions are always evaluated to strings and are best suited for composing dynamic text content.

Variable Access

Simple variable

{{myData.name}}

Nested property

{{myData.profile.email}}

Array access

{{myData.items.[0]}}

Built-in Helpers

if

{{#if myData.isActive}}Welcome back!{{/if}}

if/else

{{#if myData.isAdmin}}Admin Panel{{else}}User Panel{{/if}}

unless

{{#unless myData.isBlocked}}Access granted{{/unless}}

each

{{#each myData.users}}{{this.name}}, {{/each}}

each with else

{{#each myData.items}}{{this}}{{else}}No items{{/each}}

with

{{#with myData.user}}{{name}} ({{email}}){{/with}}

lookup

{{lookup myData.colors 0}}

Custom Helpers

You can define custom Handlebars helpers in your workflow class using the @DefineHelper() decorator. A decorated method becomes available as a helper in all template expressions of that workflow, using the method name.

Defining a custom helper

import { DefineHelper, Workflow } from '@loopstack/common'; @Workflow({ configFile: __dirname + '/my.workflow.yaml', }) export class MyWorkflow { @DefineHelper() sum(a: number, b: number) { return a + b; } }

Using the custom helper in YAML

Once defined, call the helper by its method name and pass arguments positionally:

transitions: - id: calculate from: start to: end call: - tool: createChatMessage args: role: 'assistant' content: 'The total is: {{ sum 10 20 }}'
Last updated on