Skip to content


Variables let you customize your Markdoc documents at runtime.

Here I am rendering a custom {% $variable %}

You can pass variables in a few ways:

  1. Through the variables field on your Config
  2. Via the variables attribute on a partial tag.
  3. Manually from within your Node or Tag transform functions.

Global variables

Here's an example of how you can pass variables to your config:

const doc = `
{% if $flags.my_feature_flag %}
Username: {% $ %}
{% /if %}

const config = {
  variables: {
    flags: {
      my_feature_flag: true
    user: {
      name: 'Dr. Mark'

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

which you can then access within your document:

{% if $flags.my_feature_flag %}
Username: {% $ %}
{% /if %}

With partials

To pass variables to a partial, set the variables attribute:

{% partial variables={sdk: "Ruby", version: 3} file="" /%}

and access the value within your partial file the same way you would a regular variable:

SDK: {% $sdk %}
Version: {% $version %}


Markdoc doesn't support passing variables to certain nodes, such as the href of a link Node. Instead, pass your variable to the href attribute of a custom link Tag.


[Link]({% $variable %})


{% link href=$variable %}Link{% /link %}

Next steps