I am attempting to use Jinja2 from Sphinx to allow Jinja2 macros in my rst files. The Jinja2 macro invocations are being ignored and the macro invocation is rendered as simple text in the HTML output. For example, I want to use a macro in the file index.rst
. The index.rst
file looks something like this:
{{ Abbr("URL", "Uniform Resource Locator") }}
where Abbr
is the name of the macro. I believe this is the correct way to invoke a Jinja2 macro. How do I get Sphinx to run Jinja2 against my source files?
I have incorporated a template file in the Sphinx _templates_
directory that looks like this:
{% extends !index.html %}
{# import the template file containing the macros #}
{% import MA.tmpl as tmpl %}
The file containing the macro is stored in the _templates_
directory and looks like this:
{# This macro is used in Sphinx-based documents and generates an HTML
abbreviation that can be further controlled using CSS #}
{% macro Abbr(abbreviation, expansion) -%}
<abbr title="{{ expansion }}>{{ abbreviation }}</abbr>
{%- endmacro %}