Skip to main content
Install TemplateDX and render a .mdx template against a props object. The snippets below use the Node API (load + transform + stringify). If your runtime can’t read templates from disk (browser, edge), precompile them to JSON ASTs at build time; see the last section.

Install

Render a template (Node)

Given my-template.mdx:
my-template.mdx
Run it:
Output:
  • load(path): parses the .mdx file from disk into an AST.
  • transform(ast, props): evaluates expressions and tag plugins against props.
  • stringify(ast): serializes the rendered AST back to a Markdown/text string.

Render a precompiled template (browser / edge)

transform() consumes a TemplateDX AST, not a compiled MDX component. Standard MDX loaders (@mdx-js/loader, @next/mdx, Vite MDX plugins) compile .mdx into a component function, which transform() can’t use. To render templates where you can’t read from disk, precompile them to JSON in a build step:
precompile.ts
At runtime, import the JSON and skip load:
render.ts
load bundles imported components into the AST, so precompiled templates keep working when they import other .mdx files.

Next steps

Syntax

Tags, expressions, components, and XML passthrough

Variables

Props and scope resolution

Custom tags

Write your own <Tag> plugins

Custom filters

Extend expression evaluation with filters