Is it possible to have a section, list and single template for a content folder?

Is it possible to have inside layout > posts a section.html, list.html and single.html?

Alternatively would it be possible to do the following:

layout > section > posts.html

layout > posts > list.html, single.html

I assume section is really a list so the section.html will “overwrite” list.html?

The reasoning behind my question is to have section.html be an index page and use `list.html to list all the content.

Instead of thinking about the section, think of each HTML page generated, and each of those will have a separate template lookup order.

It might seem strange, but the lookup order actually helps cut down on redundant code/templates.

So let’s say you have a section called posts:

I am explaining this because I don’t quite understand your question, but I think understanding the lookup order will solve your issue, so you can figure out which template is loading.

For section, /layouts/section/posts.html will load before /layouts/posts/list.html or /layouts/_default/list.html.

If you want to keep them next to each other, set your templates as:

  • /layouts/posts/list.html
  • /layouts/posts/single.html

And to clarify, a “section” is a type of “list”. It is built for a lot of flexibility, but you don’t need three templates for a section unless you are doing something fancy. :slight_smile:

1 Like

I was trying to do something fancy… Thank you for this. All good now.

I too am not clear as to your question, but from what I understand, you can do what you’re asking for.

See the following example: https://github.com/hnarayanan/harishnarayanan.org/blob/master/layout/projects where you can see the three kinds of layouts (with slightly different names) as in your example.

(This is independent of your question, but also note that that within this, you can filter by different sub kinds of content e.g. {{ range where .Data.Pages "Params.category" "==" "website" }}.)

Note that on another index page (like the home page), you can loop over all pages (across your different kinds of content) and get a complete list.

Thanks for the explanation and example