DEV Community

Ryan Frazier
Ryan Frazier

Posted on • Originally published at pianomanfrazier.com on

2 1

Add Tags to Hugo Theme

To add support for tags in a Hugo theme you need two pieces. One template to render the list of tags and another to render the list of everything under that tag. After wading through Hugo's documentation several times I am documentating the process here.

Hugo's template lookup order can be overwhelming. I recognize it's power, but to add a simple feature to a blog theme it can be too much.

Here is a simple way to add tag support. You will need two files.

{{/* layouts/taxonomy/terms.html */}}
{{ partial "header.html" . }}
<section>
<h1>Tags</h1>
<ul>
{{ range .Data.Terms.Alphabetical }}
<li>
<h2>
<a href="{{ .Page.Permalink }}">({{ .Count }}) {{ .Page.Title }}</a>
</h2>
</li>
{{ end }}
</ul>
</section>
{{ partial "footer.html" . }}

{{/* layouts/taxonomy/list.html */}}
{{ partial "header.html" . }}
<section>
<h1>Tag: {{ .Title }}</h1>
<ul>
{{ range .Pages }}
<li>
<h2>
<a href="{{ .Permalink }}">{{ .Title }}</a>
</h2>
<time>{{ .Date.Format (.Site.Params.dateform | default "January 2006") }}</time>
</li>
{{ end }}
</ul>
</section>
{{ partial "footer.html" . }}
Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (1)

Collapse
 
l1x profile image
Istvan

Thanks a million, this works!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay