Templates for tags

I’m tagging my pages in the front matter with things such as

tags: [ 'foo', 'bar' ]

To provide some documentation for my tags, I have pages:

  • content/tags/_index.md (an overview)
  • content/tags/foo/_index.md
  • content/tags/bar/_index.md

(This is correct, right? content/tags/foo/_index.md rather than content/tags/foo.md?)

Now I’d like to apply a different layout for content/tags/_index.md and for content/tags/foo/_index.md. I’m reading https://gohugo.io/templates/lookup-order/ which I interpret to mean that I could define:

  • layouts/categories/tags.html.html for content/tags/_index.md, and
  • layouts/categories/tag.html for content/tags/foo/_index.md

but not so.

What is the right way of doing this?

According to your config then:

tags is taxonomy kind
foo and bar are term kind

the lookup order:

  • layouts/tags/tag.html for content/tags/_index.md (Taxonomy)
  • layouts/tags/term.html for content/tags/foo/_index.md (Term) Applied to All term under tags taxonomy

(Not Tested)
If you want to apply specific template for content/tags/foo/_index.md (the term foo under tags taxonomy only), you may try to set the layout manually on content frontmatter.

the look up will be layouts/tags/<custom_layout_name>.html

1 Like

Works, thank you!

(P.S. Somebody needs to de-convolute this piece of software. Not exactly obvious …)

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.