Range within a range

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

I guess part of my confusion about slice is if you range over one, it’s just one, e.g.:

{{ $tag_array := slice .Page.Params.tags }}
{{ range $tag_array }}
  {{ . }}<br >
{{ end }}

results in [tag1 tag2 tag3] not what I’d expect:
tag1
tag2
tag3

1 Like

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

Here’s the answer:

            {{ $site := .Site.Taxonomies.tags }}
            {{ range .Params.tags }}
              {{ $tagname := lower . }}
              {{ range $name, $taxonomy := $site }}
                {{ $count := $taxonomy.Count }}
                {{ if eq $name $tagname}}
                  {{ $tagname }}<sup>{{ $count }}</sup><br />
                {{ end }}
              {{ end }}
            {{ end }}

results in:
tag13
tag25
tag39