Taxonomy terms with the original case

Hi,
with this code

{{ range $name, $taxonomy := .Site.Taxonomies.docs }}
        <ul><li><a href="{{ $.Site.BaseURL }}docs/{{ $name | urlize | lower  }}">{{$name }}</li></a></ul>
{{ end  }}

I obtain the terms of my category in lowercase:

  • term1
  • term2
  • ecc.

But the original terms are “Term1” and “Term2”. How to renders terms with the right case?

Thank you

what do you mean with “the right case”, is it original case?

if you want to render the original case then try to remove the lower

<ul><li><a href="{{ $.Site.BaseURL }}docs/{{ $name | urlize }}">{{$name }}</li></a></ul>

or use the CSS text-transform: capitalize

Use the title function:

<ul><li><a href="{{ $.Site.BaseURL }}docs/{{ $name | urlize | lower  }}">{{$name | humanize | title}}</li></a></ul>

As stated in the docs: https://gohugo.io/functions/title/

Hi @Yudy_Ananda and @benmarte thank you for your replies.

@benmarte code works, but it’s not ok for all my terms.

As a term I have in example “Valle d’Aosta”. If I use {{$name | humanize | title}} I will have Valle Daosta and not Valle d'Aosta.

How to render the term exactly for how it is originally?

Thank you

Try removing the humanize and see if that works.

No.

In general I have:

  • Valle Daosta with {{$name | humanize | title}} ;
  • Valle-Daosta with {{$name | title}};
  • valle-daosta with {{$name}}.

Instead I want Valle d'Aosta.

Thank you

This might be hacky but try using safeHTML with title maybe someone else might provide a better solution, sorry.

Thank you, but I have no idea on where to start :frowning:

I haven’t tried this. But setting preserveTaxonomyNames to true in your site config might help.

It works, thank you @kaushalmodi !

Very cool! By the way, instead of renaming the thread title with “[Solved]”, you can use the new “mark as solution” checkmark. You should see it in the “buttons row” below each post.

1 Like

Another solution right for me is this

            <ul>
                {{ range $taxonomyname, $taxonomy := .Site.Taxonomies }}
                {{ if eq "docs" $taxonomyname }}
                {{ range $key, $value := $taxonomy }}
                <li>{{ $key }}</li>
                {{ end }}
                {{ end }}
                {{ end }}
            </ul>

I have read of it here How to grouping by categories