Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variables don't work in overriden templates #200

Closed
ddorian opened this issue Jan 9, 2024 · 4 comments
Closed

Variables don't work in overriden templates #200

ddorian opened this issue Jan 9, 2024 · 4 comments
Labels
documentation Documentation is required external Concerns another part of the ecosystem useful tip A how-to, good to know

Comments

@ddorian
Copy link

ddorian commented Jan 9, 2024

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.

Copy link

github-actions bot commented Jan 9, 2024

Welcome to this project and thank you!' first issue

@fralau
Copy link
Owner

fralau commented Jan 9, 2024

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 fralau added external Concerns another part of the ecosystem documentation Documentation is required labels Jan 9, 2024
@fralau
Copy link
Owner

fralau commented Jan 9, 2024

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

@ddorian
Copy link
Author

ddorian commented Jan 10, 2024

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.

@ddorian ddorian closed this as completed Jan 10, 2024
@fralau fralau added the useful tip A how-to, good to know label Jan 10, 2024
fralau pushed a commit that referenced this issue Jan 10, 2024
  - The Jinja2 engine used for HTML templates is the
    standard one of MkDocs, and distinct from the
    macros engine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation is required external Concerns another part of the ecosystem useful tip A how-to, good to know
Projects
None yet
Development

No branches or pull requests

2 participants