Open richtera opened 3 years ago
I would agree that this couldn't be easily "changed" without making all kinds of sites fail,
You are right about that.
The current lookup rules is from more specific to the least specific, but as you have figured out, specificity is in the eye of the beholder.
My main problem is that overriding a layout of a certain output type needs to be done many times because it looks for layouts without that output type before looking at the default. But I could see an argument to consider section, type and so on the same way. Personally I had expected the lookup to follow your order except consider each filename across the folder sequence first. Therefore the more specific file inside of default would be more important than the less specific file in the posts or section folder. Would it be possible to add a programmed lookup sequence in the config maybe?
@richtera, This would be a major breaking change, so I have a few questions:
How did you work around this issue in your current use case? Or can you? Do you consider this a curious implementation detail or a fundamental flaw? How serious is the problem for you?
I have to make multiple copies of the same file to override it for each view type. It just kind of goes counter to overriding views but does work. I feel that there might be a better way to do the lookups and it might be possible to have a lookup mode type switch for each theme module.
it might be possible to have a lookup mode type switch for each theme module.
Why is that desirable? Are we trying to build an obstacle course? :wink:
My thought was that if we are looking for specific templates before less specific ones, then it should really allow a more specific template inside of _default to override a less specific template inside of the posts or view folder. For example I have a lesson.tmpl.html layout which is a template type output (it's just a document fragment I usually load using fetch from the browser) for a lesson which is now being overridden by lesson.html even though that layout is a full layout for a whole page. So unless I repeat lesson.tmpl.html in every folder I have lesson.html then it's not doing the right thing even if the tmpl.html file is the same in all cases.
I think the only thing that's really hurting is the fact that for baseof lookups in _default doesn't contain a non LANG versions in it.
If I specify both LANG and OUTPUT_TYPE on each file it works pretty well, but it maybe nicer to be able to just specify OUTPUT_TYPE. Most of the other lookups are not that necessary in that case. NOTE: This whole resolution list was generated by breaking inside of hugo when resolving a layout for a file that had an OUTPUT_TYPE other than html.
I would recommend crafting a test case to match your scenario instead of manually creating a lookup list. The largest list we currently test is about 36 entries long. See https://github.com/gohugoio/hugo/blob/b5d906e31e716328e2c0fbbdbfe6fc5b2ff98886/output/layout_test.go#L28
Ok, will check. I think the main problem I have is that if I want to specify the most specific templates using OUTPUT_TYPE I also have to provide a variation for each language since there is no default lookup for baseof with OUTPUT_TYPE but no language. I have worked around the problem by always specifying OUTPUT_TYPE on all my templates which then will override the particular _default types and they are early in the lookup order for each folder. Like post/layout.en.html.html. I am not quite sure if it makes sense to include non OUTPUT_TYPE lookups in the sequence, but that's very subjective. I didn't expect hugo to consider posts/layout.json before it would consider _default/layout.rss.json when the output type is rss but specifying all fields mostly works.
@richtera, I submitted a PR that adds some additional scenarios to the tests configuration. We max out at 80 lookups!
Hoping those help this discussion.
I traced through the layout lookup code and I found the following for lookup. The upper case values are the actual values in the post and it's folder name and output type.
And for the baseof lookup.
Although this is fairly flexible. I was expecting the sequence to be from more specific to the least specific.
For example. If I have a template
_default/LAYOUT.OUTPUT_TYPE.html
it currently does not override
section/LAYOUT.html
I would agree that this couldn't be easily "changed" without making all kinds of sites fail, but maybe there is a way to enable a new lookup mode. Ideally, it would look for the most specific layout (i.e. kind, layout, language, type, output type) in all folders and then the next least one.