Write a file path where you would write any other value, and you get a String back.
logo #= @assets/logo.svg
intro #= @docs/intro.mtf
logo is the link to your image. intro is the text of your Moth template file. Both are ordinary strings.
Putting a file in a template
image #= [$html:
<img src="[@assets/logo.svg]" alt="Moth">
]
image is a normal String. You can compose it, store it in a constant, pass it to a function and return it, exactly like any other string.
The compiler writes the URL
You never write the output path yourself. The builder decides where the file is emitted, then writes the link from the page that contains it.
The same logo becomes ./assets/logo.svg on the home page and ../../assets/logo.svg on a page two folders deep. That is why the compiler holds on to which file you meant instead of turning the path into text straight away.
Content files give you their content
A .mtf or .md path gives you what the file says, not where it lives.
license #= @legal/license.md
footer #= [$html:
<footer>[license]</footer>
]
A .moth path gives you nothing: source files hold declarations, and declarations are brought in with a dependency clause.
@helpers build_value
Unused files still count
A file path is a build dependency wherever you write it, even in a constant nothing reads. The compiler checks it exists and watches it for changes.
Reaching the output is separate. A file that no page ends up using is never copied into your site.
A direct root builder slot can use the same resource-bearing String, for example for favicon. It remains ordinary module-relative resource use, not a page URL or a .moth file value.
A file path written in expression position evaluates to a String. There is no Path type. The file kind decides how that string is built, and the compiler keeps enough structure inside it to write correct links later.
An explicit extension makes the path a file value. The same @ spelling without an extension names a dependency provider. A path followed by one symbol in expression position is a qualified reference, not a file value:
intro #= @docs/intro.mtf
name #= @settings site_name
@settings site_name
The qualified reference selects one declaration and produces its ordinary value. Keep the path and symbol on one physical line. See Dependency paths.
The file kind decides the value
intro #= @docs/intro.mtf
license #= @legal/license.md
logo #= @assets/logo.svg
- a
.mtf path evaluates to that file's compiler-owned content string - a
.md path evaluates to that file's compiler-owned content string - any other accepted file evaluates to a resource-bearing string
- a
.moth path has no file value at all
Every accepted file value above has language type String. Nothing exposes a file object, a filesystem handle or an output path to the program.
Builder slot metadata uses ordinary resource values
A direct root builder slot can receive a resource-bearing String, such as a favicon:
[$in favicon:[@assets/logo.svg]]
This is normal source resource use. The path resolves from the module root, keeps its structural resource anchor and is rendered by the builder in the document's output context. It introduces no page-URL value or new file kind; .moth remains without a file value.
The HTML builder accepts this value for favicon, while stylesheets requires exactly one tracked CSS resource. Other scalar slots accept ordinary String content. The old page_* names are ordinary constants with no implicit metadata effect.
Content files reuse their content constant
A direct .mtf or .md value is the same folded content constant a dependency clause binds. The file is compiled once, by its normal owner.
@docs/intro content as intro
same #= @docs/intro.mtf
Both forms name one compiled file and one content value. The direct form is convenient when a page needs the content once and does not need a bound name. The dependency clause is the form to use when the name matters or when the file is used repeatedly.
Whichever form is used, plain Markdown links and images inside a .md file stay literal and untracked.
.moth files have no file value
source = @helpers.moth
That is rejected. Preparation records the spelling as SourceKindNoFileValue, a structural diagnostic fact with no physical target. Stage 0 does not resolve or validate a .moth target, add semantic-source membership or create a physical-source or watch record. No filesystem target resolution occurs. AST always issues MothFileHasNoValue, whether or not a matching .moth file exists.
A .moth file exposes declarations, and declarations are consumed through dependency clauses:
@helpers build_value
Source text is never exposed as a string. A source kind may be a file value only where the language defines one canonical content string for it, which is true for .mtf and .md and nothing else.
Resource strings are ordinary strings
A resource file value is a normal String, so ordinary string rules apply.
logo = @assets/logo.svg
logo_for |name String| -> String:
if name is "main":
return @assets/main.svg
else
return @assets/fallback.svg
;
;
logos {String} = { @assets/main.svg, @assets/fallback.svg }
It may be mutable, a parameter, a return, an optional, a collection element, a map value, an exported constant or a runtime value. Nothing is rejected merely because a string names a resource.
The URL is not decided yet
Internally a resource file value is not the text "./assets/logo.svg". It carries a resource anchor, and the string stays structural until a builder knows which artefact will contain the text.
image #= [$html:
<img src="[@assets/logo.svg]" alt="Moth">
]
image is a fully folded compile-time constant even though its final characters are unknown. Composition, storage, export and template insertion all work on it.
The consequences are:
- output paths and URLs are never observable through a cast, formatter or public interface
- a compile-time operation that needs the final characters is rejected while placement is unresolved
- runtime text operations happen only after the containing artefact has resolved each anchor
There is no second source-visible string type. A resource-bearing string is a String.
URLs are rendered by the builder
Resource identity, byte source, emitted output path and rendered URL are four separate facts. The builder chooses the output path, then chooses the artefact whose URL rules observe the rendered text, and renders a relative URL from there.
resource: assets/logo.svg
context: index.html
URL: ./assets/logo.svg
resource: assets/logo.svg
context: docs/getting-started/index.html
URL: ../../assets/logo.svg
resource: assets/fonts/site.woff2
context: assets/site.css
URL: ./fonts/site.woff2
The URL context is the artefact whose URL resolution rules observe the string, not necessarily the file that contains the generated code. Page runtime code uses the active page document, standalone CSS uses the stylesheet, and inline CSS uses the page document.
Project HTML origin configuration is never prepended to a resource URL. Resource URLs are relative to their context artefact.
Site navigation is the separate case. A route is not a file the build emits, so it cannot be written relative to a context artefact and does need the origin. @/ is the origin-aware site-root string. See File paths.
Crossing a module boundary
A file value obeys filesystem ownership, so it cannot reach into a child module's or support package's private files. Content and resources cross a boundary as ordinary exported strings instead:
$export
logo #= @assets/logo.svg
$export
intro #= @docs/intro.mtf
A consumer binds those as ordinary exported String constants. Aliases and re-exports preserve the resource behind the string, so the link still renders correctly from the consumer's own pages.
Moth templates and Markdown
.mtf files remain declarationless and dependency-clause-free. A file value is used through a nested Moth template inside the implicit Markdown body.
[$html:
<img src="[@images/ownership.webp]" alt="Ownership graph">
]
- plain
@images/ownership.webp Markdown text remains ordinary text - a nested file path resolves from the
.mtf file's owning module root .mtf gains no frontmatter, no dependency clauses and no implicit root scope- a template value from a same-module helper uses a qualified reference naming the helper and one selected symbol
- plain
.md link and image targets remain literal and untracked
Rendered Markdown and HTML are never scanned to discover files.
Direct Moth-template compilation
The direct .mtf compiler service has no route and no containing output artefact, so it cannot render final resource URLs.
It returns structural folded content with its resource facts. Extracting plain text succeeds only when the folded content contains no unresolved anchors; otherwise the request reports unsupported content rather than guessing a path. A project builder consumes the structural result and applies its normal resource link plan.
Static branch specialisation
Both branches of an ordinary if complete normal validation, and a physical-target-bearing path in a branch removed by known-Bool specialisation is still resolved and validated. A SourceKindNoFileValue occurrence still reaches AST for its unconditional diagnostic but is never resolved as a physical target. That inactive branch contributes no output. A runtime branch retains ordinary reachability, so any reachable physical-target-bearing path contributes its uses. See File paths for why being a build input is separate from reaching an output.
MON data boundary
MON carries resource identifiers as ordinary strings. Resolve any compiler structural resource pieces to their final characters before encoding; an unresolved value fails conversion to concrete MON data. There is no public Resource value at the Rust boundary, and the codec performs no path discovery, URL generation, filesystem checks or resource loading. No string scan reconstructs dependencies. That contract is Rust-only serialised-data documentation. See MON format.
Concepts related to file values