Skip to content

block extracopyright not overriden #2508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
EdouardThiel opened this issue Mar 29, 2021 · 5 comments
Closed

block extracopyright not overriden #2508

EdouardThiel opened this issue Mar 29, 2021 · 5 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@EdouardThiel
Copy link
Contributor

EdouardThiel commented Mar 29, 2021

Hello,

extracopyright doesnt work for me:

  • I have added custom_dir: overrides after the material theme in mkdocs.yml
  • also added an overrides/main.html file:
{% extends "base.html" %}

{% block htmltitle %}
<title>This is a title</title>
{% endblock %}

{% block extracopyright %}
This is my extra copyright
{% endblock %}

The title works, but the extracopyright outputs nothing; that's because in base.html the block footer includes partials/footer.html and currently, includes doesn't override blocks.

Is it possible to correct the templates with a variable or a macro instead of a block extracopyright? or a special way to import footer.html ?

For instance replace the block in footer.html by

        Made with
        <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
          Material for MkDocs
        </a>
        {{ extracopyright }}

or even better, define extracopyright in the config (like copyright) and so in footer.hml it would be

        Made with
        <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
          Material for MkDocs
        </a>
        {{ config.extracopyright }}

without having to write an overrides/main.html file.

@squidfunk
Copy link
Owner

squidfunk commented Mar 29, 2021

Thanks for reporting!

But it outputs nothing, because the block footer includes "partials/footer.html" and currently, includes doesn't override blocks.

That's correct, that's a limitation of Jinja we completely forgot about 😅 I don't think we should add another variable in mkdocs.yml, because we already have copyright and adding extracopyright is kind of confusing. I think the best thing we can do is remove the template block, because currently it has no use. You can override footer.html, if you wish to.

@EdouardThiel
Copy link
Contributor Author

But it would be very simple to replace it by

        Made with
        <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
          Material for MkDocs
        </a>
        {{ extracopyright }}

and then, in overrides/main.html, write

{% extends "base.html" %}

{% block htmltitle %}
<title>This is a title</title>
{% endblock %}

{% set extracopyright %}
This is my extra copyright
{% endset %}

It works nice, and the main advantage is that I don't have to broke the footer logic, nor froze the footer.html with a modifed copy!

EdouardThiel added a commit to EdouardThiel/mkdocs-material that referenced this issue Mar 29, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Replace the extracopyright block,which doesnt' work, by a variable `{{ extracopyright }}` that can be set e.g from `overrides/main.html` with `{% set extracopyright %} ... {% set %}`; see issue [`squidfunk#2508`](squidfunk#2508)
@XhmikosR
Copy link
Contributor

XhmikosR commented Apr 4, 2021

@squidfunk I also hit this in pi-hole/docs#491 and I agree that overriding a block is a lot easier and less work to keep in sync than the whole template, especially for people not too familiar with the syntax :)

squidfunk pushed a commit that referenced this issue Apr 10, 2021
Replace the extracopyright block,which doesnt' work, by a variable `{{ extracopyright }}` that can be set e.g from `overrides/main.html` with `{% set extracopyright %} ... {% set %}`; see issue [`#2508`](#2508)
@squidfunk
Copy link
Owner

I merged both PRs. This will be available with the next release.

@squidfunk squidfunk added bug Issue reports a bug resolved Issue is resolved, yet unreleased if open labels Apr 10, 2021
@squidfunk
Copy link
Owner

Released as part of 7.1.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

3 participants