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
- 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:Custom Dependencies
You can extend the template engine with additional libraries. All custom dependencies are automatically namespaced under the$ object:
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
- Jinja2 Template Engine - The template syntax inspiration
- Deno Runtime - The JavaScript runtime used for expression evaluation
- Lodash Documentation - Utility library documentation
- Day.js Documentation - Date manipulation library
- Voca Documentation - String manipulation library
- Numeral.js Documentation - Number formatting library