_index.md ignores type for layout rendering

I have a question related the type property in the front-matter for _index.md files.

Althought I’ve read the realeted posts https://discuss.gohugo.io/t/-index-md-pages-in-section-taxonomies-etc-are-not-rendered-using-single-html-template/5466 and https://discuss.gohugo.io/t/static-page-in-content-not-rendering-correctly/5427/16 I’m not really more clever.

Assuming a project where you have the following content-Structure:

content
  |-- zurich
  |  |-- _index.md
  |  |-- venue-a.md
  |  |-- venue-b.md
  |-- amsterdam
  |  |-- _index.md
  |  |-- venue-a.md
  |  |-- venue-b.md
  |-- new-york
  |  |-- _index.md
  |  |-- venue-a.md
  |  |-- venue-b.md

All venues and citites (sections) have the same structure so according to DRY I was thinking about having the following layout structure:

layouts
  |-- city
  |  |-- list.html
  |-- venue
  |  |-- single.html

and assigning the appropriate front-matters to a _index.md and the venue-x.md files like:

_index.md

title = "Zurich"
type = "city"

venue-xyz.md

title = "Venue XYZ"
type = "venue"

(obviously I’ve made a reduced front-matter example without date, description etc. above just to get the idea.)


Well, the venue-Layout (Single) renders as expected however the city-Layout does not really work out and fall back to the _default/list.html-layout or using the section layout like layouts/section/zurich.html or layouts/section/amsterdam.html

I am wondering if I miss something or this functionality is planned in the future or what are the reasons to ignore the type for _index.md-files?

Any help or hints in the right direction are welcome.

I’m not 100% I caught all of that, but I think your mistake is that you are treating _index.md as a single page, when it’s actually a list page…hence why it’s falling back to _default/list.html. That said, you can work around this within your existing templates by leveraging features like kind or just using content views…

Okay, so I should use the kind-Property for stuff like this. Unfortunately I’m a bit lost with the new kind property.

As far as I understood the changes in v0.18 correct with a sentence like Everything is a Page now. and you have access to the Front-Matters of _index.md on the list pages.

I’m unclear how to control the layouts with the new kind property. Could you give me a short hint how I should change the content and layout organisation to achieve a matching result?

Given the above stated content-structure I try to achieve the following:

/zurich/ <- an index page listing all venues within this folder
/zurich/venue-a <- A detail page for venue-a (works well)

/amsterdam/ <- an index page listing all venues within this folder
/amsterdam/venue-b <- A detail page for venue-b (works well)

2 Likes

Hmm. If this is all you want, I think this is just standard for Hugo and you don’t need to do kind or content views. I thought you were asking for something much more complex. Why not just put one template at layouts/section/zurich.html that lists all the zurich pages and then another at layouts/section/amsterdam.html…but I can see how that wouldn’t be the most flexible and easy to use if you have, for example, folders for 100 cities :smile:

But it looks like @bep is on it with this type/layout issue to get what (I assume from your original post) you want done in terms of source organization. Also, he recently committed this enhancement for v20, which will at least make the lookup order for sections more consistent (and therefore less confusing). Here are the docs on content views as well, although this won’t respect “type” necessarily, you could have another front matter variable to check for in your list.html and then use .Render to show the appropriate view…

I have not read all of this, but also note the small but important recent change I did with the section layout selection. With the latest dev version you can put

/mysection/single.html
/mysection/list.html

Etc.

@rdwatters - Yes, this is what I did to overcome the current situation, but I definitely want to avoid creating the same template file named like the section folder. This will end up in a huge mess of repeating code. (Yes, there will be hundreds of cities in the project)


When I read the documentation for Single-Layouts properly where the type is included in the orders.

Single:

/layouts/TYPE/LAYOUT.html
/layouts/SECTION/LAYOUT.html
/layouts/TYPE/single.html
/layouts/SECTION/single.html
/layouts/_default/single.html
/themes/THEME/layouts/TYPE/LAYOUT.html
/themes/THEME/layouts/SECTION/LAYOUT.html
/themes/THEME/layouts/TYPE/single.html
/themes/THEME/layouts/SECTION/single.html
/themes/THEME/layouts/_default/single.html

why not to follow the same structure for the list-Pages like:

> /layouts/TYPE/list.html
> /layouts/SECTION/list.html
/layouts/section/SECTION.html
/layouts/_default/section.html
/layouts/_default/list.html
> /themes/THEME/TYPE/list.html
> /themes/THEME/SECTION/list.html
/themes/THEME/layouts/section/SECTION.html
/themes/THEME/layouts/_default/section.html
/themes/THEME/layouts/_default/list.html

Okay, a valid point is where to put the LAYOUT for lists is unclear to me, since I’ve never used it.


Cool, thanks for this. As far as I see it - this helps to organize section-templates better, but as a developer you still need to create a section in your layouts for each section you have. Even they are equal in the structure.

Haha, I mentioned that :wink:

I think that’s what bep is trying to do with the issue he just opened for the project, as mentioned above.

Right now, you can create individual list files at layouts/section/sectionname.html that fall back on layouts/_default/section.html and then to /layouts/_default/list.html.

There are lots of ways to keep this DRY, even with the current limitation of section pages not respecting type and layout…you can use partials, etc…I guess the question is how many unique/different layouts are you planning on having in this site?