What _index.md should look like for a new section?

Hi, I am new to Hugo and amateur programmer. I am using hugo to generate an educational site and so far it works very, very well. I use hugo-universal theme. I am adding a new content section (apart from the existing blog, which I will also keep) called competency (should be competencies, but I could not get it to work). It sort of works, but did not have the section title - like /blog/ has “BLOGS” on top.

With time I will crack it, but it struck me how I could not get an example _index.md file anywhere. People talk about how it is rendered but do not say what should be in it. My current understanding is that _index.md serves as a kind of terminating point for a section. I was so confused about it that at first I pasted code from _defaults/list.html page there; then I had it empty. and lastly I added frontmatter with title = “Competencies” and it worked! But what else should I keep in _index.md type file for a section?

And thanks very much for the absolutely excellent Hugo project!

You need _index.md to let Hugo know that it’s a section. And you need index.md if you want to make a page bundle. It’s very well described here: https://gohugo.io/content-management/page-bundles/#readout

Our friend @regis wrote a great post about this too: https://regisphilibert.com/blog/2018/01/hugo-page-resources-and-how-to-use-them/

I appreciate that. However what should be the content of _index.md? For a new section, for example.

By the way I found it very helpful to read: https://www.zeolearn.com/magazine/develop-a-theme-for-hugo

In general some Front Matter is enough:

---
title: Some title
description: Some description
---

If you want to put content in there as well that’s fine. You’ll call that with {{ .Content }} in the template.

The _index.md provides the url for the section as well. But again, that’s all in the docs. I got it from there as well.

I know it is in the docs, but I have read quite a bit of that already so some human help was very handy. Thanks.

If you want to know about some specific Hugo things I recommend the blog from @regis. He wrote some in depth articles about very important Hugo features like bundles, pipeline etc.

1 Like