fralau / mkdocs-macros-plugin

Create richer and more beautiful pages in MkDocs, by using variables and calls to macros in the markdown code.
https://mkdocs-macros-plugin.readthedocs.io
Other
318 stars 50 forks source link

Variables don't work in overriden templates #200

Closed ddorian closed 7 months ago

ddorian commented 7 months ago

Using the simple example https://mkdocs-macros-plugin.readthedocs.io/en/latest/#simple-example

The defined variable in mkdocs.yml:

plugins:
  - search
  - macros:
      on_error_fail: true
      on_undefined: strict
extra:
    unit_price: 10

Prints black string ` when put as{{ unit_price }}` in an overridden template.

It works in this format though {{ config.extra.unit_price }}.

The problem is that it doesn't cause an error with the configuration above but prints blank string.

github-actions[bot] commented 7 months ago

Welcome to this project and thank you!' first issue

fralau commented 7 months ago

It is important to note that Mkdocs-Macros was designed as a Jinja2 template engine for the markdown documents.

It is entirely distinct from MkDoc's Jinja2 templating engine for the html templates.

You can, to a limited extent, make the two interact: here is the description of the "state of the art" on how to "trickle" values from a markdown page to an html template.

I wasn't aware that the config object was present in the standard Mkdocs Jinja2 engine. If that's the case, then yes, {{ config.extra.unit_price }} would work! That's not a feature of Mkdocs-Macros, but of MkDocs itself.

The fact that a non-existent variable gives an empty string does not suprise me (by contrast, the Mkdocs-Macros template engine would display an error message in the page, in that case). If you wish to know how to change that behavior (if that's possible), you would have to consult the the MkDocs documentation, or open a question or issue on their project repository.

fralau commented 7 months ago

If the point about {{ config.extra.unit_price }} is confirmed, that would definitely deserve to be documented under the paragraph HTML pages.

ddorian commented 7 months ago

It is entirely distinct from MkDoc's Jinja2 templating engine for the html templates. If you wish to know how to change that behavior (if that's possible), you would have to consult the the MkDocs documentation, or open a question or issue on their project repository.

Thank you.

If the point about {{ config.extra.unit_price }} is confirmed, that would definitely deserve to be documented under the paragraph HTML pages.

Just tested and this works with default mkdocs, without the plugin.