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 }}

<div>Categories</div>
 
{{ 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 }}

<div>Category</div>

{{ the category ink }}

else

{{if in more than one category}}

<div>Categories</div>

{{ 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.