How to get full name of Tag?

I’m using this code to display list of tags (with posts):

{{ $data := .Data }}
{{ range $key,$value := .Data.Terms.ByCount }}
<h2><a href="{{ $value.Name | urlize }}">{{ $value.Name }}</a> {{ $value.Count }}</h2>
{{ range $value.Pages.ByPublishDate }}
  <li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
{{ end }}
{{ end }}

For example Tag “Fast and Furious 8” will be displayed as “fast-and-furious-8”,
How can I display full tag name (Fast and Furious 8)?

You can use humanize and then the title filters…

I know about humanize, but it is not what I’m searching for.
Tag “fast-and-furious-8” will be “Fast and furious 8”. Not “Fast and Furious 8”.

In which layout do you want to show that?

  • _default/single.html
  • _default/terms.html

I think your code already does what you want. Which version of Hugo are you using?

1 Like


I’m using latest, 0.24.1.

Oh, got it. Add this to your config.toml:

preserveTaxonomyNames = true

Man, you save me again! Thank you!

Config works too and is a better solution :smile:

And @Avaray, yes you know about humanize, but that’s not all I put there so you should read my full comment: I also mentioned title, which also would have given you what you wanted.

1 Like

I readed… but I was not sure what did you mean with that title.
So I leaved that and I was browsing documentation, working with my theme… and in meantime @MunifTanjim gave me answer :stuck_out_tongue:

For future reference and anyone who finds this thread in search, you can take any hyphenated/dasherized/urilized string and do the following:

{{$hyphenated := "john-doe-random-quote"}}
{{humanize $hyphenated}}
=> "John doe random quote"
{{(humanize $hyphenated) | title }}
=> "John Doe Random Quote"
{{(replace $hyphenated "-" " ") | title}}
=> "John Doe Random Quote"
1 Like

@rdwatters, you are right. Your way also works properly :slight_smile:

1 Like