Since about 2017 (per this discussion) users have been unwittingly using partialpartialCached (and likely inline partials) without including an extension.
For example, using {{ partial "example" . }} should actually be {{ partial "example.html" . }}
Impact
Difficulty for contributors supporting a mistake both on current and future features (from this @bepissue comment):
We support partial lookups without suffix for historical reason, and that was a mistake we cannot take back
I wonder if we could make this a WARN or ERROR — I was unaware that not using .html was not best practice, in fact I thought the opposite was true (that is that it was better to avoid the .html ) — by default, and have a config option to increase to fatal, and/or remove the warning.
Perhaps this could be just a WARN and maybe a slow depreciation.
Actually there was a comment by Bep recently on an issue on Github about that (not sure if that is in your links). It’s unintended but a feature - the gist of it. I made it my own rule to always have an extension in any partial call for a while now. I DO NOT think you will be able to get this made into a “feature” (the phasing out), but maybe having some form of bash script that checks templates and complains about missing file extension and linking to that post every time the topic will come up might help adding some “hygiene” to the issue and future layout samples.
I guess a first step is to go through the docs site and add extensions to all samples of partial and partialCached.
This is an example of a “we can be a little flexible here, how can that hurt?” … and then some years later.
This is an example of the main lesson I’ve learned working with Hugo. Flexibility comes at a cost and should be really important or be obviously without future negative side effects.
This would impact a lot of projects in the wild I’m guessing. On a related note, how does Hugo decide which partial to call when using {{ partial “components/example” . } when components/example.html and components/example.js both exist? Is there a lookup order for partials? (Docs are giving a 503 right now so I apologize if its’ mentioned already)
Ah. In that case maybe the definition of what is ‘best practice’ needs to be more clearly considered and articulated. In fact, I wonder if partialCached requiring .html is what could be considered a bug in light of this consideration.
This may have been true at some point, but unless I’m missing something it is not true today.
git clone --single-branch -b hugo-forum-topic-30244 https://github.com/jmooring/hugo-testing hugo-forum-topic-30244
cd hugo-forum-topic-30244
hugo
grep EXAMPLE public/index.html
grep EXAMPLE public/index.txt
This example has two output formats, with a home page template for each format. Each template makes this call:
The partial template should be under: /layouts/partials/example
(no suffix in the filename)
The template call should be:
{{ partial "example" . }}
There are 2 Output Formats in my project HTML & RSS.
The example partial is outputted in both.
Try it and see with your own eyes.
P.S. I didn’t test your sample repo as my time is limited (I had to post in this topic though, since I really care about the current behavior and I don’t want to see it changed).
How are you going about with minimising code duplication across different output formats?
In any case I am not recommending anything.
I’ve found that if I need to update a template frequently and keep it as a single file for all Output Formats, then the above method is the simplest that I’m aware of.
That’s interesting. I do distinctly remember that I was not able to output a .html partial when called from an RSS template back in Dec 2020, hence the above.