Skip to content

Variables

Variables allows you to enter a string that references a key/value pair stored in the mkdocs.yml file. This allows you to change the value in the mkdocs.yml file and have that variable applied to all topics that reference it when you build your site.

A great use for variables is content that changes, like a version number, a copyright date, or product names.

Using Variables

  1. Install the MkDocs Macros plugin using pip.

    pip install mkdocs-macros-plugin
    
  2. In the mkdocs.yml file, add the following information.

    plugins:
        - search
        - macros
    
  3. In the mkdocs.yml file, create your key/value pair where the key will be used in your variable and the value is what replaces the variable when you publish your site or run it locally. In the example below, version is the key and 1.0 is the value.

    extra:
        version: 1.0
    
  4. In a topic, use {{ config.extra.<key> }} where <key> is the key you created in the mkdocs.yml file.

    Example:

    {{ config.extra.version }}