A .mtf file sees compile-time constants from its module root and @html helpers.
A constant capture
export:
site_name #= "Moth"
;
-- docs/intro.mtf
# Welcome to [site_name]
The compile-time constant is inserted into the Markdown at that position.
A nested $raw override
[$raw: Raw HTML here
]
Nested templates default to $md, but an explicit directive overrides that.
A .mtf file sees a small compile-time scope. The implicit template body can access constants from its module root and builder-provided helpers.
Same-directory module root constants
Exported compile-time constants and const records from the same-directory module root are visible inside a .mtf file. This is the primary way to parameterise moth template content.
export:
site_name #= "Moth"
;
-- docs/intro.mtf
# Welcome to [site_name]
Builder-provided compile-time helpers
Exported compile-time constants and const records from @html are visible flat inside a .mtf file. This includes helpers such as p, codeblock and other HTML builder constants.
-- docs/intro.mtf
[p: This paragraph uses the @html p helper.]
[codeblock, $code("moth"): value = 42]
Collision semantics
@html constants and same-directory module root constants don't shadow each other. If both surfaces expose the same visible name, compilation fails with a visible-name collision diagnostic. The collision identifies both sources where location data is available.
Authors resolve collisions by renaming the module-root export.
export:
p #= [: Custom paragraph]
;
export:
my_p #= [: Custom paragraph]
;
The collision occurs when the same-directory root and implicit @html surface are combined for a .mtf body.
This follows the same no-shadowing model as ordinary source visibility.
Implementation gap
The accepted collision model rejects same-name imports from both surfaces with a visible-name diagnostic. The current compiler resolves some collisions through local-over-HTML precedence rather than diagnosing them. Stage B of the language documentation plan removes the overwrite path and registers both surfaces through one visible-name registry. See Progress for the recorded drift.
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: Raw HTML output
]
Constants versus runtime values
Only compile-time constants are visible inside a .mtf file. Runtime bindings, runtime functions, types, traits, methods, external runtime APIs and the generated self content constant are not visible.
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
All template directives available in the compile-time template environment are valid inside .mtf. This includes $md, $raw, $fresh, $html, $code, $css and $escape_html.
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 work only where the builder environment provides them. Do not assume arbitrary normal source imports are available inside .mtf.
Related concepts