You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature Request: Extend the on_page_context event with the reference to the Jinja2 Environment #3709
I've proposed different changes in the linked Issue, basically proposing that the Post (Page-like) object should have a reference to the Blog instance it was created with. This would allow to pass the whole page object to the "date" filter and the function could be then instance aware and use the post_date_format from the correct instance.
squidfunk wants to abide to proper plugin-development standards, so before hacking a solution together he wanted me to report it here first. Personally, I don't see an issue if he decided to put a self.env reference in the plugin in the on_env and later use it in on_page_context, but I also agree it would be nice for it to be the MkDocs-approved approach 😉
Filters can be decorated with pass_context (and also pass_environment, but the former is enough). So if you attach the blog instance to each post, the date (meta) filter can use it to access the right date formatting function.
Activity
pawamoy commentedon May 20, 2024
Filters can be decorated with
pass_context(and alsopass_environment, but the former is enough). So if you attach the blog instance to each post, the date (meta) filter can use it to access the right date formatting function.Something like that :)
But it still feels a bit like a workaround.
on_envand multiple plugin instances do not play well together indeed.