Determine one or more post categories?

In summary.html, I’m using this if statement to determine if a post is in any categories, and if so, showing the category archive page link or links.

{{ if .Params.Categories }}

{{ with .Params.Categories }}
{{ range . }}
<a href="{{ "/categories/" | relLangURL }}{{ . | urlize }}/">{{ . }}</a>
{{ end }}

{{ end }}

But I want to be able to output the grammatically correct “category” for one category or “categories” for more than one.

How can I determine if the post is in either one post or more than one, and output the correct “category” or “categories.”

Something like this:

{{ if .Params.Categories }}
{{ if in one category }}


{{ the category ink }}


{{if in more than one category}}


{{ all the category links }}

{{ end }}

you can try

{{ $Len := len .Params.Categories }}
{{ if gt $Len 1 }}Categories{{else}}Category{{end}}

Thanks, that works great.

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