Managing separate tags for multiple sections

Hello, I’m a really new to using Hugo, so I apologise in advance for my inability to use technical terms that well.
Hugo version: v0.140.0
Theme: Blowfish

The website I’m working on has two sections, one being /blogs (under content/blogs) and the other being /notes (under content/notes). Each of them have multiple entries, essentially acting like two separate blogs. I’m not having an issue with the display, however, the major issue that is coming up is the fact that, every one of these entries under the both of them have tags, which are currently served at /tags. However, this is an issue for me, as I wish the tags for the two different sections to be separate, preferably to be situated individually at /blogs/tags and /notes/tags respectively. After going through the documentation and the forum, I tried using categories to maybe segregate the two but it did not end up working. And I’m not entirely sure how to use the taxonomies feature for the same, despite going through various forum posts. I would like some help about the same. Thank you in advance! :smile:

site configuration

[taxonomies]
blog_tag = 'blog_tags'
note_tag = 'note_tags'

[permalinks.taxonomy]
note_tags = '/notes/tags/'
blog_tags = '/blogs/tags/'

[permalinks.term]
note_tags = '/notes/tags/:slug'
blog_tags = '/blogs/tags/:slug'

content/blogs/blog-1.md

+++
title = 'Blog 1'
date = 2024-12-20T07:33:41-08:00
draft = false
blog_tags = ["John Burroughs"]
+++

content/notes/note-1.md

+++
title = 'Note 1'
date = 2024-12-20T07:33:47-08:00
draft = false
note_tags = ["John Muir"]
+++

layouts/_default/single.html

{{ define "main" }}
  <h1>{{ .Title }}</h1>
  {{ partial "tags.html" . }}
  {{ .Content }}
{{ end }}

layouts/partials/tags.html

{{ $taxonomy := "tags" }}
{{ if eq .Section "blogs" }}
  {{ $taxonomy = "blog_tags" }}
{{ else if eq .Section "notes" }}
  {{ $taxonomy = "note_tags" }}
{{ end }}

{{ with .GetTerms $taxonomy }}
  <p>Tags:
    {{ range . }}
      <a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
    {{ end }}
  </p>
{{ end }}

And to make sure we get a nice title when visiting /blogs/tags and /notes/tags, add this to your site configuration:

[[cascade]]
title = 'Tags'
[cascade._target]
path = '{/blog_tags,/note_tags}'
1 Like

Hey! Thanks a lot for helping me out with this. It is working😁.
Just to see if I understand what we’re doing (I hope you know you don’t mind me asking this, I just want to be sure if I’m understanding everything right so that I can work with this better), so basically in this solution, we’re creating two tag equivalent taxonomies, blog_tag and note_tag, and then basically ensuring that we have the respective */tags using permalinks, and setting up a tags page for each of them with our overrides. And we’re adding the cascade to site config to put up the title for visiting */tags (because without it, blog_tags and note_tags come up it seems). Right?
Thank you again for your reply!

Bingo.

1 Like

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