Ampersand in taxonomy term

I have a site that uses tags as a taxonomy.

One blog posts has the following definition in its frontmatter:

tags:
- Simon & Garfunkel

The template that renders the tags in the post contains:

{{ with .Params.tags }}
    {{ range sort . }}
        {{ $href := print (absURL "tags/") (urlize .) }}<a href="{{ $href }}">{{ lower . }}</a>
    {{ end }}
{{ end }}

This creates a link to /tags/simon-garfunkel. But the taxonomy term page is created at simon--garfunkel.

I read about a site config value preserveTaxonomyNames but cannot find it in the documentation.

Does anyone know how I can match the taxonomy page slug to the one of the link that’s created? So either the page is created at /tags/simon-garfunkel or I get the link to match /tags/simon--garfunkel.

have a look at that one

1 Like

Oh, missed that one. Thank you.

For anyone else stumbing across this, the preserveTaxonomyNames configuration option was removed 6 years ago in v0.55.0.

1 Like

@jmooring pointed me to GetTerms, which works perfectly:

{{ with .GetTerms "tags" }}
    {{ range sort . }}
        <a href="{{ .RelPermalink }}">{{ lower .LinkTitle }}</a>
    {{ end }}
{{ end }}

Instead of passing the title through the strings.ToLower function, you might consider configuring your site so that it doesn’t capitalize or pluralize list titles for pages without a backing file.

https://gohugo.io/configuration/all/#capitalizelisttitles
https://gohugo.io/configuration/all/#pluralizelisttitles

I’ll check it out. Thank you!

1 Like

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