Categories separated by commas

How could I refactor this code so that the categories are separated by commas?

                {{ $categories := .Params.categories }}
                {{ $all_categories := .Site.Taxonomies.categories }}
                {{ with $categories }}
                <span class="post-categories">Categories: 
                    {{- range $all_categories -}}
                        {{ if in $categories .Page.Title }}
                        <a href="{{- .Page.Permalink -}}">{{ .Page.Title }}</a>&emsp;
                        {{ end }}
                    {{- end }}
                </span>
                {{ end }}

I am a “beginner” at Hugo.

I don’t see any categories (that’s one of the default taxonomies).

You’re right. The code I pasted is wrong, I’ve fixed it now (clipboard issue - I posted everything too fast without stopping to look)

Anyway, I don’t handle {{ range }} and would like to know how I could refactor that code so that the categories are separated by commas.

{{ $something := slice "a" "b" "c" }}
{{ range $k, $_ := $something }}
  {{- if $k }},{{ end }}
  {{ . }}
{{- end }}

result

a, b, c

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