Sphinx Jinja is a Python library that enables the embedding of Jinja2 templates directly within Sphinx documentation. It allows dynamic content generation, variable injection, and custom logic using Jinja2 syntax in reStructuredText or MyST files. The current version is 2.0.2, and releases are generally made as needed, with significant changes between major versions.
pip install sphinx-jinjaVerified import paths — ran on the pinned version, not inferred.
To get started, add 'sphinx_jinja' to your `extensions` list in `conf.py`. Then, configure Jinja contexts, filters, globals, and environment options using `jinja_contexts`, `jinja_filters`, `jinja_globals`, `jinja_tests`, and `jinja_env_kwargs` variables. Finally, use the `.. jinja::` directive in your reStructuredText or MyST files to render templates. The provided example shows a `conf.py` setup and a conceptual `.rst` usage.
Migrate your `conf.py` configuration from `jinja_contexts`, `jinja_env`, `jinja_filters`, `jinja_globals`, `jinja_tests` (pre-2.0.0) to the new style using `jinja_contexts`, `jinja_filters`, `jinja_globals`, `jinja_tests`, and `jinja_env_kwargs` (2.0.0+). Consult the official documentation for detailed migration guides.
Ensure your project is running on Python 3.7 or a later version before upgrading to sphinx-jinja 2.x.
Upgrade your Sphinx installation to version 4.0.0 or higher: `pip install 'sphinx>=4.0.0'`.
Upgrade your Jinja2 installation to version 3.0.0 or higher: `pip install 'Jinja2>=3.0.0'`.