Pass Frontmatter to Taxonomy Without _index.md

Here is how I enter front matter in taxonomy pages these days without the use of _index.md

I create a partial and call it from within the <head> tag of my templates.

<title>{{ partial "title.html" . }}</title>

Then this partial contains a long list with the following:

{{ if in (.Permalink | string) "/some-taxonomy-URL/" }}<---- custom meta ---->{{ end }}

I much prefer having one file with a long list of page titles rather than several folders that contain various _index.md. At least for me it’s easier to maintain.

Also this technique can be used for creating layouts in any Hugo section or taxonomy you need from within the /_default/layouts/list.html/

I’m well aware of the Hugo’s template lookup order but I much prefer to have one template to rule all lists, rather than having several templates in different directories.

Also this technique is fast. Meaning that I haven’t noticed any differences between organizing the templates as is recommended by the Hugo Docs and the way that I just mentioned above.

2 Likes