Adding a title to a tag (taxonomy) page

I use the following code for my tags.html which I took from here:

{{ $taxonomy := "tags" }}
{{ with .Param $taxonomy }}
    {{ range $index, $tag := . }}
    {{ with $.Site.GetPage (printf "/%s/%s" $taxonomy $tag) -}}
	/ <a href="{{ .Permalink }}"> {{ $tag | urlize }}</a>
      {{- end -}}
    {{- end -}}
{{ end }}

I have little understanding as to what this code means, I made it work with help from someone at mastodon at the time.

This create a page similar to this one. There’s a <hr> line at the very top, and I’d like to have the title of the tag (so in this example, the title woudl read “blogging”). Better, I’d like to get rid of the <hr> and have a dotted border under the <h1> tag for the title, which is how my theme works for the blog.

How do I go around doing this? I tried to enter a text after the <li> html tags, right before the <a href="{{ .Permalink }}"> {{ $tag | urlize }}</a> but when I save and hugo server refreshes I see no results.

Ok, so I went really primitive here trying to figure out the code. I saw that adding text after the <li> tags had no effect, however, it did have effect on my main page. So, what I’m looking at is not the code that renders page with the list of tags, but what just creates the tags and adds tags to my posts.

OK… so my next guess is that Hugo (from what I read in the docs) creates taxonomies like these automatically, there is in fact no html page called “tags” or whatever that makes the page with the list of tags, that’s just another list page, like the other list page templates in Hugo. OK, ok, things falling into place a bit. I still don’t get the code I’m looking at, but I understand that what I want has nothing to do with it in the first place.

So now what I need is to modify the page list template. There’s a list page and there’s a single page. If I modify the right page, I can create the title I want.

But how does it know to create the dates at the end of the links of the page of tags…? That’s not a part of the list page.

I figured it out…
list.html was not something I played with a lot before, but there it was. The code in there was made way more sense as to what I see on the screen:

{{ define "main" -}}
<ul class="posts">
{{ range .Data.Pages -}}
    <span><a href="{{ .Permalink }}">{{ .Title }}</a> <time class="pull-right post-list" datetime="{{ .Date.Format "2006-01-02T15:04:05Z0700" }}"> / {{ .Date.Format "2006-01-02" }}</time></span>
{{- end }}
{{- end }}

at the top, there is my <hr> and well, if I want to add a title, all I need is the page title which is {{ .Title}}' (because as I realized, Hugo is generating these taxonomies automatically, so it "knows" the title of the page I'm looking at is the page of the taxonomy. Now all there's left to do is to wrap the {{ .Title}}’ with <h1> tag to get the style I want and… that’s it!

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