Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

myst-substitutions

A small MyST plugin that replaces Nunjucks-style {{ var }} tokens using values from project config and page frontmatter.

Define a value once and reuse it across your documentation.

Basic usage

Enable by adding the .mjs file for the latest release of this plugin in your myst.yml plugins configuration:

myst.yml
project:
  plugins:
    - https://github.com/choldgraf/myst-substitutions/releases/download/v0.1/index.mjs

Define key/value pairs in project or page metadata:

page.md
---
substitutions:
  myvar: "**Wow!**"
---

Then insert it with {{ var }} syntax in your MyST markdown:

MyST Demo
Here's a styled variable: {{ myvar }}.


Here’s a styled variable: Wow!.

Here are a few examples of how to use it:

MyST Demo
Welcome to {{ site_name }}.

Style variables in their definition: {{ brand_emphasis }}.

Or style them in your content: **{{ site_name }}**.


Welcome to MyST Docs.

Style variables in their definition: MyST Docs.

Or style them in your content: MyST Docs.

This even works in headers:

MyST Demo
### Header variable: {{ site_name }}


Header variable: MyST Docs

Configuration

Define substitutions at either the project-level (in myst.yml), or in page frontmatter. Page-level configuration over-rides project-level configuration. Here are examples from these docs:

myst.yml
project:
  title: "MyST Substitutions"
  github: https://github.com/choldgraf/myst-substitutions
  plugins:
    - ../dist/index.mjs
    - https://raw.githubusercontent.com/jupyter-book/myst-plugins/main/plugins/demo/src/index.mjs
  substitutions:
    brand_emphasis: "**MyST Docs**"
    version: "v1.3"
    site_name: "MyST Docs"
    release_channel: "stable"
    items:
      - name: "Alice"
        role: "Chair"
      - name: "Bob"
index.md
---
substitutions:
  version: "v2.0"
  meeting_date: "2025-02-01"
  meeting_date_literal: "`2025-02-01`"
  release_channel: "preview"
---

Page-level over-rides

Override or add values per page with frontmatter. This page sets version, meeting_date, and overrides release_channel.

MyST Demo
Latest release: {{ version }}.

Next meeting: {{ meeting_date }}.

Channel for this page: {{ release_channel }}.


Latest release: v2.0.

Next meeting: 2025-02-01.

Channel for this page: preview.

Nunjucks filters

Nunjucks Filters work too:

MyST Demo
Shout it: {{ site_name | upper }}!

Fancy filters: {{ site_name | replace("Docs", "is totally cool") | upper }}


Shout it: MYST DOCS!

Fancy filters: MYST IS TOTALLY COOL

Multi-line substitutions with the {substitution} directive

Use the {substitution} directive for multi-line content like lists and tables that can’t be expressed inline:

MyST Demo
:::{substitution}
{% for item in items %}
- **{{ item.name }}** — {{ item.role }}
{% endfor %}
:::


  • Alice — Chair

  • Bob — Secretary

This works with tables too:

MyST Demo
:::{substitution}
| Name | Role |
| --- | --- |
{% for item in items %}| {{ item.name }} | {{ item.role }} |
{% endfor %}
:::


NameRole
AliceChair
BobSecretary

Known limitations