Geht wählen! Am 26. September 2021 ist Bundestagswahl in Deutschland, wählt Annalena Baerbock für zukunftssichere Klima-, Digital- und Sozialpolitik.. Mehr infos zum Wahlprogramm auf gruene.de 🗳💚🌻

Hugo: ignore _index.md in list templates

How I ignore _index.md files in my list templates

Written by Kevin Gimbel on , 🍿 1 min. read

While creating my new website I also added more sections, namely a blog, photography, and art section. All of these use list templates and render "article"-like content previews. I wanted to add some content to these lists and Hugo has a special file named _index.md for that. This file can be used to create index pages for lists.

When I did that I somehow also included the index files in the post listings which was not what I wanted, so I added a if statement to my article-preview.html template that is used to render article previews.


<article class="article article--in-list" aria-labelledby="article-heading-">
[...]
</article>

`` checks if the file name is not _index.md - this will ignore all _index.md files from being rendered with the article-preview.html template.

It does the job but feels wrong and hacky, so if you know a better solution, please let me know on GitHub or Mastodon.

Hi, I'm Kevin!

I'm a DevOps Engineer with a focus on automation and security. Before shifting into DevOps and cloud computing I worked as Front-End Developer, which is still a hobby and field of interest for me.

Hand-made vector avatar of Kevin Gimbel

I'm very passionated about a variety of games - digital, boardgames, and pen & paper; and also interested in Sci-Fi, Cyberpunk, and dystopian books. You can find out more on the about page.