A constant template is finished during compilation.
title #= "Moth"
heading #= [$md:
# [title]
]
A direct top-level const template in an active HTML module root can also become part of the generated page:
#[$md:
# Compile-time heading
]
Const template loops have an iteration limit so an accidental build-time loop cannot run forever.
A template can be required to finish during compilation.
Named const templates
A normal constant binding can hold a folded template string.
site_name #= "Moth"
heading #= [$md:
# [site_name]
]
This creates a compile-time String value.
It does not contribute a page fragment by itself.
Direct top-level const fragments
In an active HTML module root, the direct top-level const-template form contributes a compile-time page fragment.
#[$md:
# Compile-time heading
]
The direct form:
- is valid only as top-level entry-selected fragment syntax
- must fully fold
- records its position relative to entry-selected runtime fragments
- is handed to the project builder
- never becomes HIR runtime code
Const template if
#[if show_heading:
Visible heading
[else]
Hidden heading
]
A const-required template if validates every branch body.
The selected result must fold completely.
Const template loops
#[loop items |item|:
[item]
]
Const range and collection loops may use structural break and continue controls:
#[loop items |item|:
[if item.done:
[break]
]
[item]
]
They use the project config guard:
template_const_loop_iteration_limit
The default is 10_000.
The maximum accepted configured value is 1_000_000.
The configured value must be a positive folded Int. Zero, negative values and values above 1_000_000 are rejected.
A const conditional loop folds to no-output only when its condition is compile-time false.
A compile-time true condition and a runtime or unknown condition are rejected because the compiler does not prove loop termination.
Runtime template control flow remains owned by Template control flow.