Skip to content

Guard against page is None in mkdocs theme override Jinja2 templates#202

Merged
timvink merged 2 commits intomasterfrom
copilot/update-mkdocs-theme-documentation
Feb 22, 2026
Merged

Guard against page is None in mkdocs theme override Jinja2 templates#202
timvink merged 2 commits intomasterfrom
copilot/update-mkdocs-theme-documentation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 21, 2026

Some mkdocs page types (e.g. in the readthedocs theme) set page to None, causing build errors when templates access page.meta.* unconditionally.

Changes

  • tests/fixtures/basic_project/docs/overrides_mkdocs_theme/content.html — add page and guard before page.meta.git_revision_date_localized
  • docs/howto/override-a-theme.md — update the mkdocs theme example snippet with the same guard for both git_revision_date_localized and git_created_date_localized

Before:

{% if page.meta.git_revision_date_localized %}
    <small>Last update: {{ page.meta.git_revision_date_localized }}</small>
{% endif %}

After:

{% if page and page.meta.git_revision_date_localized %}
    <small>Last update: {{ page.meta.git_revision_date_localized }}</small>
{% endif %}
Original prompt

This section details on the original issue you should resolve

<issue_title>Provide better documentation for customizing mkdocs theme</issue_title>
<issue_description>I think this page in the docs is a little out-of-date/doesn't provide the best information.

Updating the docs and/or directing users to https://timvink.github.io/mkdocs-git-revision-date-localized-plugin/howto/override-a-theme/#__tabbed_1_2 could be more useful as it is the more "correct" way of overriding/customizing the default mkdocs theme (or the readthedocs theme).

Additionally, customizing the "readthedocs" mkdocs theme with this snippet:

{% if page.meta.git_revision_date_localized %}
    <small>Last update: {{ page.meta.git_revision_date_localized }}</small>
{% endif %}

resulted in build errors because page is sometimes None for some page types with this theme. The minimum fix I chose was:

{% if page and page.meta.git_revision_date_localized %}
    <small>Last update: {{ page.meta.git_revision_date_localized }}</small>
{% endif %}
``` </issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: timvink <5570380+timvink@users.noreply.github.com>
Copilot AI changed the title [WIP] Update documentation for customizing mkdocs theme Guard against page is None in mkdocs theme override Jinja2 templates Feb 21, 2026
Copilot AI requested a review from timvink February 21, 2026 19:03
@timvink timvink marked this pull request as ready for review February 21, 2026 19:09
@timvink timvink merged commit c23ca25 into master Feb 22, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide better documentation for customizing mkdocs theme

2 participants