Tags Within Sections

I wanted to add a tags taxonomy on a section-by-section basis, where those tags appear not under root/tags/[tag_name] but root/[section]/tags/[tag_name].

This wasn’t totally obvious (but is, sort of? in hindsight) — the trick is to just write the tag as follows in your config.toml (let’s assume the section you want the tags under is called ‘blog’):

  tag = 'blog/tags'

And then, in the front matter for items in your /content/blog directory:

- tag_1
- 'tag 2 with spaces'

Then, when you visit: https://root/blog/tags it will display /layouts/taxonomies/list.html.

My expected behavior before digging into this was the following:

  • Add [taxonomies] tag=‘tags’ to config
  • Just add tags to the front matter of any item within a section
  • hugo would auto-generate the section/tags/ section/tags/tagname lists automatically
  • I guess this is because I consider sections to be discrete elements / blocks of content, and wouldn’t expect to want to list tags / categories between them on a root level

Anyway, just a tip in case anyone else is searching for how to do this. (I didn’t see this technique explicitly mentioned in other threads.)

I have the feeling that that dash / will lead to issues at some point. In TOML you need to put the taxonomy name in quotation marks so they are valid:

some/thing = error
"some/thing" = ok

There is another option where you could just set the permalink of the taxonomy in your config:

tags = "/blog/tags/:slug/"

The only disadvantage would be that you have to define one taxonomy for each section that you want to have tags in and that might end you up with weird taxonomy names like tags2 or tags_section.