Hugo

Section-based tags

I want to know if it is possible to have section-based tags (or any kind of taxonomy, really.)

An example:

I have a homepage with a blog and a portfolio of work, so blog and work sections. I write a blog post about Golang and tag it ‘golang’. I also make an app using Golang, include it in my work portfolio, and then tag it ‘golang’. I don’t want to see both the post and the portfolio piece when I look at a /tags/golang - ideally, I would have a URL that looks like /blog/tags/golang with its own view specific to blog posts and then a URL that looks like /work/tags/golang with its own view specific to portfolio pieces. Is this possible in Hugo?

I was working on a blog with tags not entered as front matter. Something like automatic tags. Idea was a Hugo driven blog with each post as a simple text file only, nothing else (no front matter, no shortcodes, no HTML in content), but that would operate like a standard blog.

The method I used could be a starting point for your issue. Using the .RelPermalink variable along with the split template function to create tages based on content location.

In my case this meant the blog posts needed to have a foolder hierachy matching the category / subject / tag /etc, and it also meant cross-tagging a post (with two different subjects) was not possible. But this sounds like what you want.

same problem I met as @hanna .

I have tag gohugo for post in section-A and Section-B, when I click the gohugo tag in section-A, I would like to list all pages tagged gohugo in section-A; when click gohugo tag on a section-B page, list all pages tagged gohugo in section-B.

Is it possible or what kind of method should I use?

@Mikhail thanks a lot for your quick help.

I have Partial template tags.html as follows, and works fine.

<div class="tag-list">
{{ range .Params.tags }}
<a href="{{ relURL (print "/tags/" . | urlize) }}" class="tag-link">{{ . }}</a>
{{ end }}
</div>

After that I tried your suggestion(also read the gohugo docs for eq )

<div class="tag-list">
{{ range .Params.tags }}
{{ if eq .Section "sectionname" }}
<a href="{{ relURL (print "/sectionname/tags/" . | urlize) }}" class="tag-link">{{ . }}</a>
{{ end }}
{{ end }}
</div>

executing “theme/sectionname/list.html” at <partial “tags.html” …>: error calling partial: template: theme/partials/tags.html:6:17: executing “theme/partials/tags.html” at <.Section>: can’t evaluate field Section in type string.

if {{ if eq $.Section "sectionname" }}
no ERRO alert. but I still cant get URL like /sectionname/tag/…

Sorry, I did not understand you correctly. If you want to have different lists of pages at address /tags/golang/, then this is impossible. This list is generated by the taxonomy mechanism. You need to create an additional taxonomy (tags2, labels, etc) which will have a different address /tags2/golang/.

@Mikhail thank you for kind help.

So the conclusion for this topic should be IMPOSSIBLE at present time. [Ever I was thinking about the possibility of this way : section-A.example.com/tags/golang, section-B.example.com/tags/golang to output pages list respectively. maybe make the site more complicated?]

@bep can I consider this as a feature request?

you can of course do example.com/section-A/tags, example.com/section-B/tags, …

You just need to design those templates manually… They would be like any other section page (not taxonomyTerm pages).

You can even go further, and have: example.com/section-A/tags/tag-foo… but things will start getting messy there… you will need to create a filter list of posts with tag tag-foo specific to that section-A. So you will need a hard-coded template for each section X tag.

@kaushalmodi thank you for quick feedback and kind help.

So the good news and bad news to the topic :smile:

Yeah, taking your suggestion into consideration.

Seems going forward to the target :smile: though I still try to find out what method I should use for working it out.

Yes, I could understand it and thanks for instruction.

Oh, ever I guess this topic could be solved by breadcrumb template, but didn’t try it out.
When I see the word hard-coded, got a little headache :crying_cat_face: