Overview
The Template Playground supports custom logic in templates through TypeScript formulas, conditional blocks, and data transformation features. This allows you to create dynamic templates that go beyond simple variable substitution.TypeScript Formulas
Formulas enable you to execute TypeScript code directly within your templates to perform calculations, transformations, and other dynamic operations.Basic Formula Syntax
Use the{{% %}} syntax to embed TypeScript expressions:
Example: Character Count
Here’s a complete example that calculates the length of a string: Concerto Model:Formula with Current Time
You can use JavaScript date functions in formulas:Formulas are executed during template generation and have access to all template variables in scope.
Conditional Logic
Conditional blocks allow you to render content based on conditions.Clause with Condition
The#clause block with a condition attribute enables conditional rendering:
Model:
true.
Optional Blocks
The{{#optional}} block provides a cleaner syntax for optional content with else branches:
List Processing
Ordered and Unordered Lists
Generate markdown lists from array data: Ordered List:Join Block
The#join block formats arrays as natural language with locale and style options:
narrow: Minimal formattingshort: Abbreviated formattinglong: Full formatting (default)
conjunction: “and” (default)disjunction: “or”unit: No conjunction
["CAR", "ACCESSORIES", "SPARE_PARTS"], outputs:
Advanced Techniques
Accessing Nested Properties
Access nested object properties using dot notation:Combining Formulas and Conditionals
You can use formulas within conditional expressions:Complex Calculations
Formulas support complex TypeScript expressions:Best Practices
- Keep formulas simple: Complex logic is harder to maintain and debug
- Use conditionals for optional content: Leverage
#optionaland#clauseinstead of inline conditions - Test with edge cases: Verify behavior with empty arrays, undefined values, and boundary conditions
- Document custom logic: Add comments in your template to explain non-obvious formulas
- Validate data structure: Ensure your Concerto model accurately reflects the data your formulas expect
Debugging Custom Logic
When custom logic fails, check:- Variable scope: Ensure variables referenced in formulas are in scope
- Data types: Verify the data matches your Concerto model types
- Syntax errors: Check for typos in formula expressions
- Condition evaluation: Test that conditions return boolean values
Next Steps
- Explore Markdown Transform to understand the template rendering pipeline
- Review TemplateMark Syntax for complete formula reference
- Check out sample templates with custom logic in the playground