Templating
Fragments and prompts support Mustache templating for dynamic content.
Basic Syntax
Use double braces for variable substitution:
fragments: project-info: content: | # {{PROJECT_NAME}} Guidelines This project uses {{LANGUAGE}}. Team: {{TEAM}}Built-in Variables
These variables are always available:
| Variable | Description |
|---|---|
CTXLOOM_ROOT | Project root directory (parent of .ctxloom) |
CTXLOOM_DIR | Full path to .ctxloom directory |
fragments: paths: content: | Project root: {{CTXLOOM_ROOT}} Config location: {{CTXLOOM_DIR}}Defining Variables
In Profiles
variables: PROJECT_NAME: "my-app" LANGUAGE: "Go" LOG_LEVEL: "debug" TEAM: "backend"In Config
profiles: quick: variables: MODE: "fast"Variable Inheritance
When using parent profiles, variables inherit and can be overridden:
variables: LANGUAGE: "Python" FRAMEWORK: "FastAPI" LOG_LEVEL: "info"
# child.yamlparents: - basevariables: PROJECT_NAME: "my-app" # New variable FRAMEWORK: "Django" # Override parent # LANGUAGE and LOG_LEVEL inherited from baseMustache Features
Simple Variables
Hello, {{name}}!Sections (Conditionals/Lists)
variables: FEATURES: - auth - logging - metrics DEBUG: true{{#DEBUG}}Debug mode is enabled.{{/DEBUG}}
Features:{{#FEATURES}}- {{.}}{{/FEATURES}}Inverted Sections (Falsy Check)
{{^PRODUCTION}}This is not production - be careful!{{/PRODUCTION}}Raw Output (Unescaped)
{{{HTML_CONTENT}}}Comments
{{! This comment won't appear in output }}Error Handling
- Undefined variables: Logged as warnings, rendered as empty
- Render failures: Original content returned unchanged
- All variables are strings: Converted to
map[string]interface{}
Examples
Project Context
# Profilevariables: PROJECT: "api-server" LANGUAGE: "Go" VERSION: "1.0"
# Fragmentcontent: | # {{PROJECT}} (0.5.4)
This {{LANGUAGE}} project follows these standards: - Use gofmt for formatting - Write tests for all public functionsConditional Content
# Profilevariables: USE_DOCKER: true CI_PLATFORM: "github"
# Fragmentcontent: | ## Deployment
{{#USE_DOCKER}} Build with: docker build -t app . {{/USE_DOCKER}}
{{#CI_PLATFORM}} CI runs on: {{CI_PLATFORM}} {{/CI_PLATFORM}}List Iteration
# Profilevariables: REVIEWERS: - Alice - Bob - Charlie
# Fragmentcontent: | ## Code Review
Reviewers: {{#REVIEWERS}} - {{.}} {{/REVIEWERS}}Best Practices
- Use descriptive names -
PROJECT_NAMEnotpn - Document required variables - Use
variables:field in fragments - Provide defaults in profiles - Avoid undefined variable warnings
- Keep templates simple - Complex logic belongs in code
- Use sections for optionals -
{{#VAR}}...{{/VAR}}handles missing gracefully