Overview
The Template Playground uses a multi-stage transformation pipeline to convert TemplateMark templates into final HTML output. Understanding this pipeline helps you debug issues and create more sophisticated templates.Transformation Pipeline
The transformation process involves several stages:Stage 1: TemplateMark to TemplateMarkDOM
TheTemplateMarkTransformer parses your template markdown and converts it into a document object model (DOM).
Source Code Reference: src/store/store.ts:85-92
- Parses markdown syntax
- Identifies TemplateMark blocks (
{{}},{{#block}}, formulas) - Validates template syntax against the Concerto model
- Creates an intermediate DOM representation
Stage 2: TemplateMarkDOM to CiceroMark
TheTemplateMarkInterpreter generates CiceroMark by binding data to the template.
Source Code Reference: src/store/store.ts:96
- Binds JSON data to template variables
- Evaluates formulas and conditional logic
- Processes blocks (loops, conditionals, joins)
- Produces CiceroMark with resolved values
Stage 3: CiceroMark to HTML
Thetransform function converts CiceroMark to the final HTML output.
Source Code Reference: src/store/store.ts:100-107
- Parses CiceroMark JSON structure
- Applies markdown formatting rules
- Converts to HTML elements
- Returns final HTML string
Core Components
TemplateMarkTransformer
From@accordproject/markdown-template package.
Purpose: Converts markdown text with TemplateMark syntax into a structured DOM.
Key Methods:
fromMarkdownTemplate(content, modelManager, type, options): Parse template
TemplateMarkInterpreter
From@accordproject/template-engine package.
Purpose: Executes template logic and binds data to produce CiceroMark.
Key Methods:
generate(templateMarkDom, data): Generate output from template and data
- Requires a
ModelManagerinstance - Data must conform to the Concerto model
- Template must reference a valid model type
Transform Function
From@accordproject/markdown-transform package.
Purpose: Converts between markdown formats (CiceroMark, CommonMark, HTML, etc.).
Signature:
ciceromark: CiceroMark JSONciceromark_parsed: Parsed CiceroMarkmarkdown: CommonMarkhtml: HTML outputpdf: PDF output (requires additional setup)
Rebuild Logic
The playground implements a debounced rebuild function to handle real-time editing. Source Code Reference:src/store/store.ts:77-108
- Debouncing: 500ms delay prevents excessive rebuilds during typing
- Strict mode: Model validation is enabled
- External models: Automatically resolves and loads imported models
- Error propagation: Errors bubble up to the error handling system
State Management
The rebuild process integrates with Zustand store for state management. Source Code Reference:src/store/store.ts:255-266
agreementHtml: Stores successful transformation resulterror: Stores error message if transformation failsisProblemPanelVisible: Auto-opens problem panel on errors
Performance Considerations
Debouncing
The 500ms debounce prevents unnecessary rebuilds:- Reduces CPU usage during rapid typing
- Prevents UI jank from too-frequent updates
- Allows batching of multiple edits
Async Processing
All transformation stages are asynchronous:- Non-blocking UI updates
- Better handling of long-running operations
- Enables proper error handling
Advanced Transformations
Custom Transform Options
You can customize the transform behavior:Multiple Output Formats
Generate multiple formats in a single transform:Format Conversion
Convert between markdown formats:The transformation pipeline is stateless. Each rebuild creates a fresh ModelManager and interpreter instance.
Debugging Transformations
Enable verbose logging to see detailed transformation steps:- Parsing details
- Model validation messages
- Transformation steps
- Timing information
Common Transformation Issues
Model Not Found
Symptom: Error about missing or invalid model type Solution: Ensure the third parameter matches your model namespace:Data Binding Failures
Symptom: Variables not rendering or type errors Solution: Validate your data structure matches the Concerto model exactlyMalformed CiceroMark
Symptom: Transform fails with parsing errors Solution: InspectciceroMarkJson structure before passing to transform()
Next Steps
- Learn about Error Handling in the transformation pipeline
- Review Template Engine API for detailed API docs
- Explore Custom Logic to understand what happens during data binding