HUGO

How to add {{.Content}} to a Taxonomy page?

Let’s say for example that I have ‘How To’ and ‘Tags’. I would like to add a short description at the top of the page preferably in markdown. Do I just hard code it with html inside terms.html or is there a way I can use markdown and use {{.Content}} ?

Add it to terms.html like this ?

<h2>Introduction</h2>
<p>I have something to say about 'How To' and 'Tags' right here.</p>

Or is there a markdown file I could use like _terms.md ?

## Introduction

I Have something to say about 'How To' and 'Tags' right here.

Render the markdown inside the html could also be a possibility. With a single.html and list.html I can easily render content with index.md and _index.md, is there something for taxonomy markdown that I can use? I only have a few taxonomies but I could see how it would require some automation for someone who has lot of them. Rendering different pages for different terms.

content

+++
title = "Test"
date = 2021-04-03T05:16:02-07:00
draft = false
tags = ["foo"]
+++

To add content or front matter to the taxonomy page:

hugo new tags/_index.md

To add content or front matter to the term page:

hugo new tags/foo/_index.md

Make sure the related templates contain the .Content field, something like…

layouts/_default/taxonomy.html
layouts/_default/term.html

{{ define "main" }}
<h1>{{ .Title }}</h1>
  {{ .Content }}
  {{ range .Pages }}
    <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
  {{ end }}
{{ end }}
2 Likes

Thanks, that makes sense. What if I wanted to add the same paragraph {{.Content}} to all the terms?

Just leave this in terms.html?

<p>This is a paragraph that I want in all the term pages. </p>

I can’t create a terms/_index.md, I don’t think that is vaild. However, what you mentioned does work for individual terms like tags/_index.md and categories/_index.md. I could just do if page is terms render this content, partial, or markdown…

content/tags/_index.md

+++
title = "Tags"
date = 2021-04-04T21:53:17-07:00
draft = false
termContent = "Labore commodo non est tempor Lorem aute occaecat ad nostrud. Laboris non occaecat sint occaecat pariatur eu. Eu reprehenderit ex ipsum sit commodo veniam velit ad et ex in commodo. Cupidatat ipsum et non nostrud exercitation nulla nulla fugiat quis est aliquip. Qui nisi sunt nostrud excepteur sint nostrud do aliquip eu eu eiusmod ut nulla laboris."
+++
This is content/tags/_index.md

layouts/_default/term.html

{{ define "main" }}
  <h1>{{ .Title }}</h1>
  {{ .Parent.Params.termContent }}
  {{ range .Pages }}
    <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
  {{ end }}
{{ end }}
1 Like

Your solution solves my problem but what’s the difference in _default/taxonomy.html and _default/terms.html ? It looks like I can modify both ‘categories’ and ‘tags’ with any of these templates.

I proposed code for _default/term.html (singular), not _default/terms.html (plural).

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