Hugo: ignore in list templates

How I ignore files in my list templates

Published on 01/3/2020 | 3.01.12020 HE

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 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.

{{ if ne .File.LogicalName "" }}
<article class="article article--in-list" aria-labelledby="article-heading-{{ .File.UniqueID }}">
{{ end }}

{{ if ne .File.LogicalName "" }} checks if the file name is not - this will ignore all 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.



Like this?

This website contains no advertisement, no tracking, no paid articles, and no shady-things-whatsoever. It is just content, provided free of charge and with accessibility in mind.

If you would like to support me in providing content - and code - for free or if this page has helped you or your company, consider supporting me directly.

You can support me via:

A colorful image of me wearing my DIY mask. The image has a colorful glitch effect.

Kevin Gimbel

is a DevOps Engineer and avid (Video) Gamer. He’s also interested in Sci-Fi, Cyberpunk, and dystopian books.

Wearing a mask is a good idea!

You can find out more about me if you wish.