Arrays, aka slice, just don’t seem to act like arrays in everyother scripting language I’m familiar with (and there are other unanswered posts here wondering the same: Range tags within a section).
Anyway, I’m trying to list out the tags (.Page.Params.tags) on a post. Easy enough, however, I’m trying to count how many other posts each tag is attributed to. I’ve tried slicing the .Params.tags and having those be the inner or outter range, I’ve tried having .Site.Taxonomies.tags be the inner or outter range. I’ve tried to range where, etc. I tried to make sure all were lower case, etc. Help.
My internal logic says this should work, but it doesn’t and there’s no output. Maybe scope?
{{ $tagAr := slice .Page.Params.tags }} # [tag1 tag2 tag3]
{{ range $name, $taxonomy := .Site.Taxonomies.tags }}
{{ if in $tagAr $name }}
<li>{{ $name }}<sup>{{ $taxonomy.Count }}</sup></li>
{{ end }}
Getting there. This will only show .Page.Params.tags that are in .Site.Taxonomies.tags, but can’t quite figure out the tag.Count part to indicate how many other posts share the same tag:
{{ $site := .Site.Taxonomies.tags }}
{{ range .Params.tags }}
{{ $tagname := lower . }}
{{ range $key, $value := $site }}
{{ if eq $key $tagname}}
{{ $tagname }}<sup>count</sup><br />
{{ end }}
{{ end }}
{{ end }}