Taxonomy Name in .Site.Taxonomes.*

I’ve been working on a simple theme, and as part of my navigation partial I’m doing this:

{{range $k, $_ := .Site.Taxonomies.categories}}
<li><a href="/categories/{{urlize $k}}/">{{humanize $k}}</a></li>
{{end}}

This basically works, but if I have a multiple-word category name, it only capitalizes the first letter. Even if I had a function to capitalize the first letter of every word in the name (which I don’t think exists in Hugo’s templates, does it?), it would pose a problem if I had intentionally uppercased only certain words in the category name. Is there any way in my template to explicitly access the name and permalink for a taxonomy item instead of having to try to derive them from the map key?

It does. Try this…

{{range $k, $_ := .Site.Taxonomies.categories}}
<li><a href="/categories/{{urlize $k}}/">{{$k | humanize | title}}</a></li>
{{end}}

Right. There are ways around this…probably some more clever than the following.(replaceRE springs to mind.) Let’s say you want to replace “And” with “and”:

{{range $k, $_ := .Site.Taxonomies.categories}}
<li><a href="/categories/{{urlize $k}}/">{{replace ($k | humanize | title) "And" "and" }}</a></li>
{{end}}

Not tested because I’m supposed to be doing my actual job right now :wink: HTH

1 Like