Skip to content


Markdoc uses partials to reuse content across documents. A separate Markdoc file stores the content, and it's referenced from within the partial tag.

Here's an example of including the file as a partial.

{% partial file="" /%}

Registering partials

You define partials by creating a mapping from the file name to an abstract syntax tree (AST) node in your config object. The default partial tag looks at this config to include the right content.

/** @type {import('@markdoc/markdoc').Config} */
const config = {
  partials: {
    '': Markdoc.parse(`# My header`)

const doc = `
{% partial file="" /%}

const ast = Markdoc.parse(doc);

const content = Markdoc.transform(ast, config);

If you want the partial tag to behave differently, you can override it in Config.tags.

Passing variables

Partials are like any other tags, so you can pass variables as attributes to them such as:

{% partial file="" variables={name: "My header name"} /%}

and access the variables as you would in a regular Markdoc document:

{% $name %}