How to loop through all the tags in every post

I want to make a tag cloud of all the tags on the home-page… but I don’t know how exactly should iterate through them.

In the single.html this worked :
{{ range (.GetTerms "tags") }} <a href="{{ .Permalink }}" >{{ .LinkTitle }}</a> {{ end}}

But this doesn’t work in the index.html

layouts/index.html

{{ define "main" }}
  {{ .Content }}
  {{ $allTags := slice }}
  {{ range .Site.RegularPages }}
    <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
    {{ range (.GetTerms "tags") }}
      {{ $allTags = $allTags | append (dict "LinkTitle" .LinkTitle "Permalink" .Permalink) }}
    {{ end }}
    <p>{{ .Summary }}</p>
    {{ if .Truncated }}
      <p><a href="{{ .RelPermalink }}">Continue reading...</a></p>
    {{ end }}
  {{ end }}
  <p>Tag cloud:
    {{ range uniq $allTags }}
      <a href="{{ .Permalink }}">{{ .LinkTitle }}</a>
    {{ end }}
  </p>
{{ end }}
1 Like

Thank you that was it , It solved my problem , I needed this part :
{{ $allTags := slice }}
{{ range .Site.RegularPages }}
{{ range (.GetTerms "tags") }}
{{ $allTags = $allTags | append (dict "LinkTitle" .LinkTitle "Permalink" .Permalink) }}
{{ end }}
{{ end }}
{{ range uniq $allTags }}
<a href="{{ .Permalink }}">{{ .LinkTitle }}</a>
{{ end }}

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