How do I display tags next to date in post?

I’m still very new to Hugo so I might just get my terms mixed. Let me explain what I want first.

On my blog, when you open a post (single.html template) there’s the <h1> title, followed by <time> that displays the time by 2006-01-02 format. Right next to the time, I’d like to have a list of the tags for this post.

The posts are tags in frontmatter tags = [“tag1”, “tag2”]
in config.tmol I do have [taxonomies] and under it tags=“tags”

in single.html I have this:
<h1>{{ .Title }}</h1> <time datetime={{ .Date.Format "2006-01-02T15:04:05Z0700" }} class="post-date">{{ .Date.Format "2006-01-02" }}</time>

What would be the Hugo syntax to add a list of tags right next to the date?

Hi,

The docs has some examples: https://gohugo.io/templates/taxonomy-templates/#example-list-tags-in-a-single-page-template

1 Like

Thanks,

still don’t understand what i’m looking at. Here’s the whole single.html as I have it now (taken from hyde originally):

 {{ define "main" -}}
{{ $taxo := "tags" }}
<div class="post">
  <ul id="{{ $taxo }}">
  <h1>{{ .Title }}</h1>
  <time datetime={{ .Date.Format "2006-01-02T15:04:05Z0700" }} class="post-date">{{ .Date.Format "2006-01-02" }}</time><li><a href="{{ .Permalink }}">{{ $taxo }}</a></li>
  {{ .Content }}
</div>
{{ if .Site.DisqusShortname -}}
<hr>
<h2>Comments</h2>
{{ template "_internal/disqus.html" . }}
{{- end }}
{{- end }}

this results in just “tags” link at the top of my post, because the code literally says $taxo is tags, but there’s nothing using the tags of the post. from this link, I’m not sure what this part is.

Well, you are only printing out $taxo in your snippet, which in this case has been set as "tags". The example I linked to has a few more lines of code involved. I would suggest you try out the whole snippet to see what that gives you. The range part in the example is what iterates over the tags.

it gives an error.

That’s ok. I’m too far out to understand what needs to be done here. I’ll figure it out.

If you just want a one-liner answer, here you go:

{{ with .Params.tags }}{{ delimit . ", " }}{{ end }}

I’d be happy to walk you through the snippet in the docs though if you want help understanding it.

2 Likes

Pointyfar,

I managed to figure it out using this article. It’s basically using the same docs in Hugo, but the way he arranged them in the post made it click in my head for some reason. I have something basic that is very slightly modified for my site now.

Thanks for trying to help. Sometimes frustration gets the best of me, especially when I’m looking at the same thing (official dogs) for hours and it doesn’t make any sense.