Skip to main content

Introduction

The template engine is a core feature of Compozy that allows you to:
  • Reference data from various workflow components
  • Perform dynamic calculations and transformations
  • Access environment variables and configuration
  • Handle conditional logic inline
Compozy uses Jinja2-style syntax combined with Deno for JavaScript evaluation, providing:
  • Simple expressions using {{ ... }} for single-line JavaScript
  • Complex logic using $exec: | for multiline JavaScript code
Since we use Deno runtime, all JavaScript code in templates follows modern ECMAScript standards and has access to Deno’s built-in security features.

Template Syntax

Simple Expressions

For basic operations, use the {{ ... }} syntax. These expressions should be concise and focus on a single operation:

Multiline Code

For complex operations that require multiple lines or intermediate variables, use the $exec: | syntax:

Working with Objects and Arrays

Built-in Functions

Compozy includes several popular libraries for common operations. Here are some examples:
For a complete reference of available functions, see Template Functions.

Custom Dependencies

You can extend the template engine with additional libraries. All custom dependencies are automatically namespaced under the $ object:
Learn more about adding custom dependencies in Custom Dependencies.

Best Practices

1

Keep Expressions Simple

Use simple expressions for basic operations:
Move complex logic to multiline blocks:
2

Use Optional Chaining

Always use optional chaining for nested properties:
3

Handle Errors

Implement proper error handling in complex operations:
4

Type Safety

Use explicit type conversions:

Next Steps

Template Functions

Explore built-in utility functions

Custom Dependencies

Learn about adding custom libraries

References