A .mtf file sees the fixed @core/html and @core/css helpers and values from helper files in the same module. It does not see module root declarations.
Selecting a helper value
site_name #= "Moth"
-- docs/intro.mtf
# Welcome to [@settings site_name]
The path names the helper file and the symbol names one compile-time value. Keep them on one line. No @mod.moth file is needed.
The selected name does not become a local name. It cannot clash with a prelude helper.
Root files stay private
A value written in @mod.moth, @package.moth or @entry.moth is not visible to a .mtf file, even when the root exports it. Move shared values into an ordinary helper file and select them with a qualified reference.
The fixed helpers
.mtf files see constants from @core/html and @core/css without a dependency clause:
[p: A paragraph.]
[h1, center: A centred heading.]
That prelude comes from the official Core @core/html and @core/css packages. It is available under every builder, not only HTML projects.
A nested override
[$raw: <div>Raw HTML here</div>]
Nested templates default to $md, but an explicit directive overrides that.
Compile-time only
Everything in a .mtf body folds during compilation. A runtime value cannot be used there. The file produces one content string and makes no page fragment of its own.
A .mtf file has a small compile-time scope. It sees the fixed template prelude and can select declarations from same-module helper files with qualified references. It has no implicit access to module root declarations.
Same-module helpers
An ordinary .moth helper declaration is reachable from a .mtf file in the same module through a qualified reference:
site_name #= "Moth"
-- docs/intro.mtf
# Welcome to [@settings site_name]
The provider path names the helper file, the selected symbol names one compile-time declaration and the two tokens stay on the same line. The template folds the selected value during compilation. The directory needs no @mod.moth file for this to work.
A qualified reference introduces no local binding. It therefore never shadows a prelude name or another declaration. Selecting @home_constants p produces that helper's p, even though the prelude also exposes p.
Root-local declarations stay hidden
Declarations authored directly in @mod.moth, @package.moth or @entry.moth belong to that root file only. A .mtf file cannot read them, even when the facade exports the declaration:
$export
site_name #= "Moth"
-- docs/intro.mtf
# Welcome to [site_name]
The unqualified name fails with a root-local visibility diagnostic instead of resolving through the facade. Naming the root file directly also fails, because root files are not qualified-reference providers.
Move the shared value into an ordinary helper file when a template needs it. A helper declaration is shared by every root and selectable from the template.
The fixed template prelude
Exported compile-time constants from @core/html and @core/css are visible flat inside every .mtf body. This includes HTML helpers such as p and codeblock, and style fragments such as center.
-- docs/intro.mtf
[p: This paragraph uses the Core HTML p helper.]
[h1, center: This heading uses the Core CSS center fragment.]
[codeblock, $code "moth": value = 42]
The prelude is fixed compiler policy under every builder, including custom SDK builders. It reads the official packages/core/html and packages/core/css Moth source packages, which are registered once as Core/MothSource roots. Each package publishes through its directly contained @package.moth. A builder cannot replace either package or change .mtf availability. Both packages precede every .mtf consumer, so a failed prelude package blocks the consumer.
The prelude supplies compile-time constants only. It is not a general template-wide import mechanism, and it never includes runtime values, types, private constants, project-local packages or arbitrary builder-registered constants. A public constant declared anywhere inside a provider package enters it under its exported name, including when another file in that package exports it with as. A re-export or alias of a declaration from another package does not.
Collision semantics
A real local binding that matches a prelude name fails with an ordinary visible-name collision. The diagnostic identifies both sources where location data is available.
A qualified selection creates no local binding, so it cannot collide merely because the selected name matches a prelude constant:
p #= "local p"
-- docs/intro.mtf
[p][@home_constants p]
The first p comes from the prelude and the second from the helper. Both render.
Nested templates
Nested templates inside a .mtf body are valid. A nested template with no explicit directive defaults to $md. Any explicit directive (such as $raw, $fresh, $html, $code, $css or $escape_html) overrides the moth template Markdown default for that nested template.
[$raw: <div>Raw HTML output</div>]
Constants versus runtime values
Qualified references inside a .mtf file must resolve to compile-time constants. Runtime bindings, runtime functions, types, traits, methods, external runtime APIs and the generated self content constant are not valid template values.
A reference to a runtime value is rejected with MOTH-RULE-0034 or MOTH-RULE-0053.
No runtime capture
Moth template bodies are const-required. There is no runtime capture. The entire body must fold at compile time.
Allowed template directives
Formatting and child-selection directives available in the compile-time template environment are valid inside .mtf. This includes $md, $raw, $fresh, $html, $code, $css and $escape_html.
A .mtf file produces one fixed content constant. It cannot expose its own slot receiver or contribute a builder root slot.
Child-template formatting boundary
Child templates are opaque barriers to the parent formatter. A child template's output is not inspected by the parent $md formatter. Template delimiters cannot pair across child boundaries.
Literal delimiter output
To output literal template delimiters, use string insertion:
["["]
["]"]
["[literal]"]
Content helpers
Content helpers such as codeblock come from the fixed @core/html prelude above, and style fragments come from @core/css. Neither comes from the active builder. A .mtf file can also name an ordinary helper with an explicit qualified reference. It does not gain that helper's declarations automatically.
Concepts related to template scope