How to render original category names (eg: with ampersands, special case, etc)?


I’m trying to render a category with an ampersand in their name using a modified version of the “mainroad” template. This is the relevant snippet (from themes/mainroad/layouts/partials/widgets/categories.html, not working):

<ul class="widget__list">
  {{- range $name, $items := .Site.Taxonomies.categories }}
  <li class="widget__item"><a class="widget__link" href="{{ "categories/" | relLangURL }}{{ $name | urlize | lower }}">{{ replace $name "-" " " | title }} ({{ $items.Count }})</a></li>
  {{- end }}

Apparently .Site.Taxonomies.categories already contains a transformed category name so I lose whitespaces, special case (eg: “CERN” becomes “Cern”), etc. Is there a way of rendering the list of categories verbatim?


Two options:

  1. Set preserveTaxonomyNames=true
  2. Add content files with Title, i.e. files for your terms
1 Like

I couldn’t find a way to use that Title (that’s set in when showing taxonomy items associated with a specific post (i.e. in single.html template)

Is there any way for doing that (without using any workaround/hacks) in current version of Hugo?

I agree that the taxonomy data model vs page data model can be a bit confusing. I have not thought too hard about this problem, but you would need to get to the content page, example:

.Site.GetPage "taxonomy" "tags" "hugo"

Which I guess is information already present in the single template.

Thanks bep@, that solved my issue. I realize this is documented on the docs but for some reason I missed it…