-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Single-page template lookup order doesn't behave as documented #3809
Comments
@geealbers thanks for this detailed report. Yes, I see what you mean and how this can be surprising. I rewrote the whole template lookup logic earlier this year to make it easier to test and extend, but I'm pretty sure that I followed the old logic. That assumption would make the documentation wrong, but looking at it now I think the current behaviour is surprising and should be changed -- and changing it should not break (too much). @rdwatters I assume you wrote the doc part on this... thoughts? |
Thanks @geealbers for pointing this out. So it seems like there are maybe two ideas being discussed here:
1 If this is a matter of just correcting the docs, I'll open up a separate issue in hugoDocs. I think the small gotcha is worth calling out; i.e., if you declare a layout and Hugo doesn't find the declared layout, it will not fall back to, in this case, 2 Using the same example, I think what you're talking about would be documented as follows, @geealbers? I'm only mentioning this for my own clarification and since @bep marked this as an enhancement:
Seems this would be a better separation of concerns for content files that that only declare a That said, with output formats, bundles, etc, my assumption is that this is a pretty big ask, @bep? Thanks! |
Thanks to you both. I think if it's not too much trouble to change the behavior and allow Hugo to always fallback to a
|
I was about to open issue for exactly this same problem... Check my post on the forum if new ideas are welcome as well, but generally speaking |
The template lookup order documentation is generated from code; it correctly describes the behavior. I suspect a number of related things have changed since this issue was created 6 years ago. |
When a page has both a
type
and alayout
, according to this example in the documentation, Hugo will look for various templates in your project that explicitly match your layout name, saylayout: grid
, but will eventually fallback to the other defaults, all the way down to/themes/<THEME>/layouts/_default/single.html
. However, the more generic fallbacks aren't actually built into the system, and if Hugo does not find a template with the explicit layout name, the page fails to build completely.Here's a sample warning you get with
--verbose
that (I assume) shows all the places Hugo tried to look for a template for rendering the given page withlayout: grid
:The inner workings of Hugo and Go are a bit beyond my skills, but the issue seems to arise in the fact that Hugo assigns any page without an explicit
layout
to be equivalent tolayout: single
. So then, the template lookup order is either going to include the custom layout value, or thesingle
default layout value, but can never include both custom andsingle
. I believe the relevant code starts inhugo/output/layout.go
lines 270–72, and then proceeds from there:I discovered the issue when trying to use the layout parameter to simply add classes to an existing page layout. (So, I didn't have or need a template file, just an
{{ if eq .Params.layout "grid" }}
call in the default page template.) This of course can be accomplished any number of other ways, but regardless, it seems like the underlying inconsistency should be addressed either by editing the documentation to match the current behavior, or by changing the Hugo layout code to match the documentation. Depending on the maintainers'/community's desired outcome.Happy to help with the documentation part, but if the the Go is to be rewritten instead, afraid I'll need to leave that to someone else.
The text was updated successfully, but these errors were encountered: