Replies: 2 comments 21 replies
-
First of all, I want to make sure that everyone is on the same page, about the distinction between the MkDocs's standard Jinja2 templating engine, and the MkDocs-Macros templating engine? The first operates on HTML files, while the second operates (much earlier on the production chain), on the Markdown source, before rendering into HTML. They are completely distinct. By default MkDocs-Macros considers the I have never tried to use MkDocs-Macros to do templating, though I guess that could kind of work (because HTML code is ignored by the Markdown parser). There is an avenue I would suggest, and that is to "trickle" values from the earlier to the later Jinja2 engine. In that way, you could import your dynamic values in the MkDocs Jinja2 template, while using the facilities of MkDocs-Macros. Is that more less what @kamilkrzyskow had in mind? |
Beta Was this translation helpful? Give feedback.
-
Wanted to share what I managed to achieve with the plugin: All the pages under this link (with exception to the ones listing sub-pages) are having content generated from Page meta using templates. Templates are included using this code snippet added as a module: def on_pre_page_macros(env):
footer = """
{% if page.meta and page.meta.api %}
{% include 'api_docs/constructor_summaries.md' %}
{% include 'api_docs/nested_class_summaries.md' %}
{% include 'api_docs/enum_summaries.md' %}
{% include 'api_docs/method_summaries.md' %}
{% include 'api_docs/constructor_details.md' %}
{% include 'api_docs/enum_details.md' %}
{% include 'api_docs/method_details.md' %}
{% endif %}
"""
env.markdown += footer Changes are not yet merged, as I'm open for feedback on improving this (One plan is to maybe have a JSON file in the future to create the necessary stuff instead of page meta, but that's not yet clear). |
Beta Was this translation helpful? Give feedback.
-
Full context: mkdocs/mkdocs#3888
My current issue is, that I'm unable to include a separate template file through the
include
option of Jinja2.I've set the macros plugin's
include_dir
todocs/.overrides/
(Can't have it outside the docs folder due to the repository's structure) and have filesapi_docs/layout.md
andapi_docs/parts/constructor_summaries.md
(relative to the mentioned include directory) set.Now, using
{% include 'api_docs/layout.md' %}
works fine when injected into the markdown through aon_pre_page_macros
python file, but{% include 'api_docs/parts/constructor_summaries.md %}
in thelayout.md
file itself returns aTemplateNotFound
error.Manually adding the include in the page is adding the content as it should, so the issue is with the template not resolving the include for some reason.
What could be possible issues?
Beta Was this translation helpful? Give feedback.
All reactions