Unleash the power of MkDocs with macros and variables
—
Configuration options for controlling plugin behavior, template rendering, Jinja2 settings, and module loading. These settings are defined in the mkdocs.yml file under the macros plugin section.
Core configuration options for module loading and rendering behavior.
# In mkdocs.yml under plugins: - macros:
module_name: str = 'main' # Python module filename for macros
modules: list = [] # List of pre-installed modules (pluglets)
render_by_default: bool = True # Render pages by default vs opt-in
verbose: bool = False # Enable verbose loggingBasic configuration:
plugins:
- macros:
module_name: custom_macros
verbose: trueWith multiple pluglets:
plugins:
- macros:
modules:
- mkdocs-macros-test
- custom-pluglet:my_module
render_by_default: falseOptions for controlling which files are rendered and where template includes are located.
force_render_paths: str = '' # Pathspec patterns to force rendering
include_dir: str = '' # Directory for {% include %} and {% import %} files
include_yaml: list = [] # Additional YAML files to loadForce rendering specific paths:
plugins:
- macros:
force_render_paths: |
docs/generated/**
api/*.md
!docs/static/**Include configuration:
plugins:
- macros:
include_dir: templates
include_yaml:
- data/constants.yml
- config/variables.yml
- nested_key: data/nested.ymlCustom Jinja2 template markers for avoiding conflicts with other systems.
j2_block_start_string: str = '' # Custom Jinja2 block start marker (default: {%)
j2_block_end_string: str = '' # Custom Jinja2 block end marker (default: %})
j2_variable_start_string: str = '' # Custom Jinja2 variable start marker (default: {{)
j2_variable_end_string: str = '' # Custom Jinja2 variable end marker (default: }})
j2_comment_start_string: str = '' # Custom Jinja2 comment start marker (default: {#)
j2_comment_end_string: str = '' # Custom Jinja2 comment end marker (default: #})Custom markers to avoid conflicts:
plugins:
- macros:
j2_variable_start_string: '<<'
j2_variable_end_string: '>>'
j2_block_start_string: '<<%'
j2_block_end_string: '%>>'With custom markers, use:
Project name: << config.site_name >>
<<% if environment.system == 'Darwin' %>>
Running on macOS
<<% endif %>>Options for controlling behavior when template rendering encounters errors or undefined variables.
on_undefined: str = 'keep' # Behavior for undefined variables: 'keep', 'silent', 'strict', 'lax'
on_error_fail: bool = False # Exit on rendering errors in CI/CD'keep' (default): Leave undefined variables as-is in output'silent': Replace undefined variables with empty string'strict': Raise exception on undefined variables'lax': Pass any unknown objects as empty stringStrict mode for development:
plugins:
- macros:
on_undefined: strict
on_error_fail: trueProduction-safe configuration:
plugins:
- macros:
on_undefined: silent
on_error_fail: falseplugins:
- macros:
# Module configuration
module_name: project_macros
modules:
- mkdocs-macros-test
- company-pluglet:shared_macros
# Rendering configuration
render_by_default: true
force_render_paths: |
docs/api/**
docs/generated/*.md
!docs/static/**
# Template includes
include_dir: templates
include_yaml:
- data/project_vars.yml
- constants: config/constants.yml
# Custom Jinja2 markers (if needed)
j2_variable_start_string: '[['
j2_variable_end_string: ']]'
# Error handling
on_undefined: keep
on_error_fail: false
verbose: trueIndividual pages can override rendering behavior using YAML front matter:
---
render_macros: true # Force rendering even if render_by_default is false
render_macros: false # Skip rendering even if render_by_default is true
---
# Page content hereInstall with Tessl CLI
npx tessl i tessl/pypi-mkdocs-macros-plugin