Layout for nested section

I’m having some trouble with Hugo’s new nested sections. I want to specify a custom layout for nested section list pages according to their parent sections, but I’m not sure where to put the layout file so that it gets used.

Let’s say I have two main sections on my site: post and book. post is a flat section, but in book I want a mix of direct items and subsections. The hierarchy looks like this:

content
├── _index.md
├── book
│   └── shortbook.md
│   └── book1
│   |   ├── _index.md
│   |   ├── chapter1.md
│   |   ├── chapter2.md
│   |   └── chapter3.md
│   └── book2
│       ├── _index.md
│       ├── chapter1.md
│       ├── chapter2.md
│       └── chapter3.md
└── post
    ├── _index.md
    ├── something.md
    ├── another.md
    └── thing.md

I want to specify a custom layout for the /book/SECTION/ (or at least for /book/book1/) list page.

As per this, I’ve tried placing a file at:

  • layouts/section/book1.html
  • layouts/book1/list.html

I’ve also tried:

  • layouts/book/book1/list.html
  • layouts/section/book/book1.html
  • layouts/_default/list.html

The last one achieves the desired effect, but has the obvious undesired side effect of changing the default list template site-wide. All the others just cause the /book/book1/ page to be rendered with the /themes/THEME/layouts/_default/list.html template.

With this being such a new feature, is what I’m trying to do possible?

1 Like

There is currently no way to have a specific template for a subsection.

If we use “Type” in front Matter, can we force the use of a specific template ?

1 Like

In general, it would be faster (and better for everyone) if you could just test your hypothesis instead of repeating an already answered question.

As I said: There is currently no way to have a specific template for a subsection (i.e. the section list pages). But it will happen, but it is not on my immediate TODO list.

Build a layout, store it for example under layouts/page, set the layout in page Front Matter and it should be taken. You can control if you put some identifying code in that template.

I had a similar issue and solved it that way.

Hello. @bep, may be we can have a specific template for a subsection now?

You can do that now via the cascade keyword. Set either type or layout and it will … cascade.