Template Lookup and the difference between _index.md and index.md

I have been working on the Nederburg for a while and finally have time to resolve some outstanding issues. At the same time I am trying to learn more about Hugo.

The issue I am working is to create a different style page from the regular post single.html for about and contact pages. Currently the contact page renders correctly with a form, but the about page is using the regular post single. The content directory structure is:

└── content
   ├── about
   │     └ index.md
   ├── contact
   │     └ _index.md
   └── posts

and the theme layouts folder is this, which is not working correctly and I cannot figure out how to set it up correctly based on Template Lookup Order.

└── layouts
   ├── _default
   │     └ list.html
   │     └ single.html
   ├── about
   │     └ single.html
   └── contact
         └ list.html

I have tried renaming about/single.html to list.html but that didn’t work unless I also rename content/about/index.md to _index.md. I feel like I am close to a solution but don’t know the right way to do it.

An index.md page uses a single template, and an _index.md page uses a list template.

Since your about page lives at the content root dir it’s just considered a regular page. So you’ll need to explicitly tell it to use the about single template.

In the front matter of your about page try setting

type: about 

Here’s a great post from @regis which should answer all your questions with regards to index.md and _index.md:

Thanks! So even though the about/index.md page is in the about sub-directory it will still use the _default/single.html template?

Is there a better way to structure the theme for this scenario?

Thanks Leo, that post will take a bit for me to wrap my head around. It seams like a lot of the themes could use a revamp to take advantage of these features. Is there a “current theme” that is kept up to date and uses the latest features and directory structure?

So this file


Is equivalent (layout wise) to this file


Which means your about page is technically living under the content root section, which will use template layouts/_default/single.html, unless specified otherwise via front matter (as in my example above).

Now, let’s say you had a file like this


Then this page would use the layouts/about/single.html template by default.

Yup. It’s Hugo Fresh Theme from @regis:

:point_up_2:That’s from @lucperkins

Well, when you say it like that it makes perfect sense! Thank you.

Also, changing the front matter and renaming a few files resolved the issue. It’s days like this that I go from thinking I understand the rendering to really flailing.

Thank you for the clarity of your answer.

Thanks! I’ll have a look.

Glad to help :+1:

Oh, sorry :crazy_face:

A post was split to a new topic: Layout lookup for Section pages