Import a .md file the same way as any other source file.
Import and use
import @docs/intro {content as intro_html}
[: [intro_html] ]
The content constant is the rendered HTML string.
Do not include the extension
import @docs/intro.md is rejected. Use import @docs/intro.
Plain Markdown content is imported with the same extensionless source import syntax as Moth and moth template source assets.
Import syntax
import @docs/intro
[: [intro.content] ]
A namespace import exposes content as a field. A grouped import brings it directly:
import @docs/intro {content as intro_html}
[: [intro_html] ]
Aliases
Use as to give the imported content a local name. This is the standard form when multiple content files are imported into the same page.
Insertion into templates and pages
Insert the imported content into a template body. The caller decides where it appears. Imported content does not become a page fragment automatically.
Import path and module visibility
Content imports follow the same path resolution and module visibility rules as normal source imports. @intro resolves from the importing file's owning module root. @docs/intro resolves from the entry root. @./... has no supported meaning. Cross-module imports require the module root's export: block to re-export the content.
No automatic page fragment
Importing a .md file and inserting its content into a template does not create a page fragment. Only direct top-level templates in an entry-selected module root become page fragments.
Direct extension imports are rejected
import @docs/intro.md {content}
This is rejected with MOTH-IMPORT-0024. Use import @docs/intro without the .md extension.
Dependency tracking
Imported content participates in normal dependency tracking. The .md file is compiled before the importing file uses its content constant.
Distinction from asset imports
.md content imports are not asset imports. They produce a compile-time content #String constant, not a tracked asset path. Markdown links and images render literal href and src values. They are not tracked assets and are not rewritten. Use normal Moth asset paths when a file should participate in tracked-asset output.
Related concepts