-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Can't extend builtin theme if it doesn't have explicit layout.html #12049
Comments
Hi @guyer - thanks for writing this report. Can I ask what your objective is and how themes relate to that, to figure out what options are available here? |
@jayaddison Sure. Due to a deeply misguided decision in my organization, I needed to come up with an in-house replacement for ReadTheDocs. Different folks in the organization have used a wide variety of sphinx themes and so I wrote things to basically make a theme that inherits from their preferred theme and makes a few modifications. For instance, I need to graft some organizational headers and footers onto the rendered pages. This has all been working for the projects I tested on, but recently somebody was using All that said, I've figured out a workaround for my project where I walk the theme bases until I find one with a |
Ok - I'm a bit confused by this in relation to the original description:
Is the (if so that should help to determine the root cause - maybe you understand and have described it already, but I'm still catching up) |
It's completely clear in my head. Isn't that good enough? 😉 I create a theme that inherits from the user's theme and customizes
{% extends "!layout.html" %} I get
{% extends "sphinxdoc/layout.html" %} I get If the user's theme is any of the other builtin classes, then, e.g.,
|
Again possibly asking things you've already figured out, but: if you configure the |
That's what I'm doing, and it doesn't work. To be explicit, here's what I do:
Alternatively,
|
Does configuring
Make any difference? |
I don't understand. |
My mistake - that should have been |
No, that doesn't work. How could it? How can a theme inherit itself? I think we must be talking past each other. The repo I'm talking about is here: https://github.com/guyer/lumache |
What happened when you tried it? |
|
Ok, thanks. Some of the documentation may need updating. I'll look at the recursion issue soon. An extremely minimal sample case -- a near-empty |
...(!) and by that I mean the original recursion issue reported - not the experimentation with the |
The repo I pointed you to, https://github.com/guyer/lumache, is exactly that. It's your lumache example (and only from Getting started), plus a bare-bones |
Ok, I've found some time to catch up on this, and have been able to replicate your findings, including the local workaround to mitigate the problem: -{% extends "!layout.html" %}
+{% extends "basic/layout.html" %} ...and that explains what you wrote here:
Slightly-off-topic: more recent versions do a better job of detecting circular theme inheritance (see 360c7a8#diff-8342bb498a7811cc5902aa78183e3b03ca43983fd66b11ce11f5f52bb64167b2R209). So the next question is: should lookups to non-existent intermdeiate template files be allowed to succeed? To answer that, I think I'll have to look at some of the code history (perhaps including the purpose of the |
Well, that's a half-truth it seems; those changes aren't yet released (they're in source control, but pending a future release).
Currently reading: https://www.sphinx-doc.org/en/master/development/templating.html#jinja-sphinx-templating-primer ... to better understand the exclamation-mark symbol as used during template loading. We should link to that section from the relevant part of the theme-development documentation. |
When using Sphinx's HTML builder, each document is written using the The base template for Meanwhile, Sphinx by-design subclasses the default Jinja template loading mechanism and overrides the That means that the initial template file-open series will be something like:
The problem is that when So somehow the logic would need to know "ok, first time you're asked for (loading them in the reverse order isn't the solution here, because we still need to look at the most-specific templates first) |
Todo: if my working so far is correct, then any use of |
Yes, that is my experience |
Thank you, @guyer - and thanks for your patience while I learn and confirm the behaviour here. I have to admit to not being familiar with the internals of theme inheritance and template loading yet, so I'm going to add the "help wanted" label to this issue in case anyone can help. I'll try to resolve it myself over the next few days, and would like to, but assistance could help. My understanding so far, to summarize for followup is:
|
A combination of both of the changes below allowed me to get things working:
With those in place, I was able to override the header section of the output HTML.
Without the exclamation-mark prefix, the build entered an infinite recursion, similar to when the template file was placed in the Without moving the template file, the build entered an infinite recursion regardless of whether the exlamation-mark prefix was used. As a user, it seems unexpected to have to place a theme-related template in the local project's |
Describe the bug
A theme that customizes
layout.html
cannot inherit from a theme that has an inheritedlayout.html
and does not explicitly have its own, e.g., default, nature, sphinxdoc, or traditional.How to Reproduce
If I add a custom theme to lumache that inherits from a builtin theme:
I get
If I change my
layout.html
to explicitly extend on the inherited layoutI get
It only works if I have
layout.html
explicitly extend on the redirectedlayout.html
Environment Information
Sphinx extensions
Additional context
Possibly related to #1792, #1794, #1884, #1885
The text was updated successfully, but these errors were encountered: