.RelPermalink not working for tags

After finishing my first ever Hugo website a few weeks back, I was trying to restart it from scratch. This was because I could rewrite the entire code which is clean, optimised and well-commented as opposed to the mess I created while learning the basics of Hugo. While doing so, I landed on a problem. I’m unable to use .RelPermalink to link to taxonomy pages. I’m displaying the posts as cards and below each card, I’m placing links to the tags it’s categorized it. I’m doing it something like (in my layouts/index.html):

{{ range where .Site.RegularPages "Section" "projects" }}

  <div> <!-- Card container -->

    <!-- rest of the code -->

    {{ range .Params.Tags }}
							
      <a href = "{{ $.RelPermalink }}">
        <p class = "tag tag-{{ . }}" uk-tooltip = "#{{ . }}">{{ . }}</p>
      </a>

    {{ end }}

  </div> <!-- /Card container -->

{{ end }}

I’m expecting the link to be something like <example.com>/projects/tag/<tag name>/. So, I have set-up the config.toml like this:

[permalinks]
  tags = "/projects/tag/:slug/"

However, when I run hugo server the links on the tags point to the home page. In the previous version of the website, I was using printf to get the link. That was something to get the job done. But, since I’m planning to keep the code clean, I don’t think using printf is a wise decision (or is it?).

Here’s my repo: https://github.com/Hrishikesh-K/Portfolio/tree/v2

Can someone please tell me if I can get .RelPermalink working here?

That is not how one would list a taxonomy’s terms on a single page.

Please have a look at: https://gohugo.io/templates/taxonomy-templates/#example-list-tags-in-a-single-page-template

In the above you are ranging through the tags parameter and $.RelPermalink points to the host root, because you are using the dollar sign.

The dollar sign is used to access the global context

That was easy, but, stupid on my part. But, isn’t index.html, that is the website’s home page, a list page? I thought, since it accepts contents from _index.md, it’s a list page too.

Yes. The homepage is by default ruled by a list template.

As per your code block above, you are rendering those terms within the context of each single page from a specific section i.e. range where .Site.RegularPages "Section" "projects"

That makes sense. Thanks a lot for the explanation.

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