Closed rodrigoschwencke closed 3 years ago
Welcome to this project and thank you!' first issue
I see where the issue is: currently the macros plugin is used to interpret macros in the markdown documents (this is the jinja2 environment).
The jinja2 engine for HTML templates is completely distinct (it is part of the standard mkdocs). It is possible to trickle variables to the template, through the page metadata.
It is, however, the first time that someone tried to use macros in the way you are trying to do.
Instead of applying the filter within the template, why don't you do it at the markdown level?
Something like this might work, in the markdown page:
---
formatted_copyright: {{ config.copyright | formatWithDate }}
---
Then you would pass the metadata as a variable to the template:
Hey :<b>{{ page.meta.formatted_copyright }} </b
But since you don't want to redefine that metadata every page, you should just ask your Python module to do it for you, automatically:
FORMATTED_COPYRIGHT = formatWithDate(env.config.copyright)
def on_post_page_macros(env):
"""
Actions to be done after macro interpretation,
just before the markdown is generated
"""
env.page.meta['formatted_copyright'] = FORMATTED_COPYRIGHT
I did it off my hat. Let me know whether that works for you?
@rodrigoschwencke How is this issue right now?
Hi, I am having problems to get the context (custom macros and filters defined in my main.py file) in a custom footer.html file. I am overriding the material-theme with this file structure :
mysite :
My main.html file contains basic stuff:
And also my footer stuff contains basically a copy of the footer.html file of the material-theme:
Main.py file:
PROBLEM - Current Behavior: I got an error "jinja2.exceptions.TemplateAssertionError: no filter named 'formatWithDate' " It clearly looks like a jinja context problem (macros and filters not passed to the jinja global context), but I can't solve it.
Precision:
Expected Behavior: I should detect both macros and filters defined in my main.py file.
CAN SOMEONE HELP ME ??? PLEEEEASE? ANY IDEA? OR CLUE?
Is this "normal"? I mean : Do macros and filters of this plugin (defined in the main.py file) only get passed to the jinja global context inside markdown files of the docs folder?? (i also tried to rename my file footer.html into footer.md: still does not work) Isn't it possible to get macros and filters inside the custom footer.html file? Hope I am being very precise. I can give more precisions if needed, please any help is welcome :)