I saw a comment by Joe with page.html instead of single.html. Is one mapped to the other?
I’m not sure about how it works under the hood, but I think this structure is the easiest to understand, at least for new users:
layouts/
├── baseof.html
├── home.html
├── page.html
├── section.html
├── taxonomy.html
└── term.html
That way, excluding the base template, there’s a one-to-one relationship between page kind and template. The structure above is what you get with hugo new theme.
Yea, I agree. Feel free to simplify/improve my example.
They’re both valid. See the table in New template system in Hugo v0.146.0
singleis a layout, currently only used for thepagekind.pageis Page kind.
For most practical applications, they work the same, but if you have both page.html and single.html, the first one will win (see the table linked to above).
So, why didn’t we remove single from the equation?
- We may get more “single kinds” in the future.
- But mostly because there’s sooooo many Hugo sites in the wild with a
single.htmlandlist.htmltemplate that changing that would create more noise than the value.
Excellent explanation. I went with page as I found it made more sense with regards to everything in content being a page.
sounds very reasonable … maybe a deprecation candidate vor v1 or when time did its work and usage of single is lesser
This sounds like a huge job at first, but I moved 6 websites to new template system and observed no issues, but instead, I found out that understanding template and what comes first is much clearer now, especially with taxonomy. Well done!
@idarek thanks, feedback much appreciated. The old setup had an extreme amount of variations, but given that, it was surprisingly inflexible. So we had to fix it, and I suspect for 99.9% of sites out there it was smooth sailing, but with many many Hugo sites accumulated over the years, it’s hard/impossible to cover all bases.
Personally, I went with this setup even in section specific folder layouts.
layouts/
├── baseof.html
├── home.html
├── page.html
├── list.html
├── taxonomy.html
└── term.html
So far so good. I also like the new layout system, especially after reading this From WordPress to Hugo, a mindset transition | Regis Philibert.
- If
page.htmlandsingle.htmlwork the same way for rendering specific pages, why this change was necessary? Section.htmlis a good naming, butlist.htmlwas basically the same?custom-folderwithin the content directory ==section.- And why does GoHugo create an additional template for taxonomies? It’s the most complicated part for me. Can I just filter necessary posts through Front Matter values? Something like:
---
tags: ["specific-tag-name"]
---
{{ range .Pages }}
{{ if in .Params.tags "specific-tag-name" }}
<h2>{{ .Title }}</h2>
{{ end }}
{{ end }}
Then why there are taxonomy.html at all..
straightforward conversion of 3 sites done without issues, very clear instructions, thanks!
As I mentioned above, this way there’s a one-to-one relationship between page kind and template, which is much easier to understand, for new users in particular.
No. There’s a one-to-one relationship between page kind and template, with fallbacks as shown below:
| page kind | template lookup order |
|---|---|
home |
home.html → list.html → all.html |
page |
page.html → single.html → all.html |
section |
section.html → list.html → all.html |
taxonomy |
taxonomy.html → list.html → all.html |
term |
taxonomy.html → list.html → all.html |
There’s a one-to-one relationship between page kind and template. If you want a list template that can be used with section, taxonomy, and term pages, create a list.html template as shown above.
Thank you, I got it!