Possible bug: Single layout for pages in v0.147.9

I run the newest version of Hugo 0.147.9 and when I have a page folder in my layouts with a single.html in it… the single in the root of the layouts folder will load for my pages (instead of the one in the page folder). This might be a bug.

Here is a minimal example: GitHub - jhvanderschee/layoutbug: Repo to prove a layout bug in Hugo v0.147.9

  • Here is why it should work: Template lookup order
  • Although the name of single.html has changed to page.html in the v0.146.0 release.
  • I tried both single.html and page.html. Both do not work (but should IMO).

The layouts/page construct, where “page” refers to the “page” page kind, is not supported with v0.146.0 or later.

This is intentional; not a bug.

See this comment from bep.

1 Like

I am having a hard time to identify where is that specific change in the linked release notes - can you help and point it out?

Thank you Joe. How would one target the the single of the Kind ‘page’ in the new template layout? Or is this no longer possible? Thank you in advance!

can you help and point it out?

Yes… you can find the new folder structure here: New template system in Hugo v0.146.0

1 Like

Thank you very much!

1 Like

How would one target the the single of the Kind ‘page’ in the new template layout?

I now use this in the page.html:

{{ if eq .Type "page" }}
  ...
{{ else }}
  ...
{{ end }}

Feels clunky to me. I would rather have a separate file.

Another problem with this approach is that is makes it impossible to not publish a page by using an empty single.html.

Also… the fact that your named layouts have to move from the page folder to the root of the layouts folder is a breaking change. Not that that is a problem… but maybe we should warn people for it.

these will render your contact page

layouts/page.single.html
        ^Kind
             ^Layout

/layouts/page.page.html
         ^Kind
              ^Type (= 'page' if not set in front matter)

if you have both layouts the first one will win

1 Like

Thank you @irkode!

However… does not seem to work for me. Can you check the code here? I created a minimal example…

Consider this content structure:

content/
├── posts/
│   ├── _index.md
│   ├── post-1.md
│   └── post-2.md
├── _index.md
└── contact.md

To create a unique template for the contact page I would do one of these…

Option 1 – Target the logical path (preferred)

layouts/
├── contact/
│   └── page.html 
├── baseof.html
├── home.html
├── page.html
├── section.html
├── taxonomy.html
└── term.html

Option 2 – Specify layout in front matter

layouts/
├── baseof.html
├── contact.html 
├── home.html
├── page.html
├── section.html
├── taxonomy.html
└── term.html

content/contact.md

---
title: Contact
layout: contact
---

Sorry… I think I wanted to have a specific layout for all ‘singles’ with .Type = page (no parent folder). Is that possible? I was mixing up .Type and .Kind. Sorry for the confusion.

Out of curiousity, why? Typically an “about” page and a “contact” page would use different layouts.

content/
├── posts/
│   ├── _index.md
│   ├── post-1.md
│   └── post-2.md
├── _index.md
├── about.md
└── contact.md

True… but sometimes they do not. The most common usecase is that you want all sections to have no single… and only publish singles for the .Type page.

I don’t understand this. Can you please clarify, perhaps with a structural example?

I had this (prior to v0.146.0):

layouts/
├── _defaults/
│   └── single.html (was empty so section singles would not be published)
├── page
│   └── single.html (was not empty, but had a nice page layout)

How do I do this in post v0.146.0? I prefer to use only 2 files.

This is an anti-pattern.

I still don’t understand this, sorry. Perhaps you can provide an example repo? The example in your initial post doesn’t seem to match the use case you describe… which is a bit unusual.

I want to target the ‘singles’ for all sections and a separate file to target the ‘singles’ that have no section and have .Type = ‘page’. This was possible prior to v0.146.0, as descibed above. If this is no longer possible then that is a valid answer.

How many content files do you have in the root of the content directory?

Why aren’t you using build options instead of the “empty template” hack?

How many content files do you have in the root of the content directory?

20+

Why aren’t you using build options instead of the “empty template” hack?

To prevent duplication in the frontmatter.

cascade