Are page.meta variables visible in templates #7555
-
I have a page with frontmatter defined. There is for instance a "documentation.layer" variable. I want to put the content of the variable in the copyright.html partial. But it doesn't show. If, in the template, I use page.meta.documentation.layer, it breaks on unknown keyword 'meta'. If I just say page.documentation.layer, it does not break, but just skips it (I'm testing on page.documentation). No error, but no variable ... Now I tried using {% if page.meta['documentation'] %}, but I still get "jinja2.exceptions.UndefinedError: 'None' has no attribute 'meta'" |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The templates and partials are Jinja2 template files that are processed after the Markdown is processed into HTML, after the macros plugin has done its work. So, this has nothing to do with macros. It just happens that the Macros plugin uses the Jinja2 syntax. I am not entirely sure why your attempt to use You could help us investigate the problem by creating a minimal reproduction. |
Beta Was this translation helpful? Give feedback.
MkDocs processes everything using the same templates, including the static template 404 page that doesn't include its own
page.meta
.Therefore before every
page.meta
access you need to validate that it exists:mkdocs-material/src/templates/base.html
Line 35 in 06fe18a
The header title also does this validation:
{% if page.meta and page.meta.title %}
iirc the
info
plugin creates the archive inon_config
event and then quits early before the template build stage.Therefore I believe you hav…