HUGO

No duplicates in Category list

Hi there,

i am new to gohugo and i’m creating my own template. Having some issues in the Category List.
I’m getting all Categories available in my posts. But i am not able to filter for duplicates.

    <div class="mb40">
    <h4 class="sidebar-title">Kategorien</h4>
    <ul class="list-unstyled categories">
        {{ range .Pages }}
            <li><a href="/{{ .Params.Categories }}">{{ .Params.Categories }}</a></li>
        {{ end }}
    </ul>
</div><!--/col-->

I tried to solve this by using GroupByParam “Categories” but then i get no output. (My Category is not in an taxonomy. I used jekyll exporter to get all my posts out of wordpress).

    <div class="mb40">
    <h4 class="sidebar-title">Kategorien</h4>
    <ul class="list-unstyled categories">
        {{ range .Pages }}
            {{ range .Pages.GroupByParam "Categories" }}
            {{ range .Pages }}
                    <li><a href="/{{ .Key }}">{{ .Title }}</a></li>
                {{ end }}
            {{ end }}
        {{ end }}
    </ul>
</div><!--/col-->

Also tried intersect… No single output… Don’t get it

<div class="mb40">
        <h4 class="sidebar-title">Kategorien</h4>
        <ul class="list-unstyled categories">
            {{ range where .Pages ".Params.Categories" "intersect" .Params.Categories }}
                <li><a href="/{{ .Params.Categories }}">{{ .Params.Categories }}</a></li>
            {{ end }}
        </ul>
    </div>

I think this is what you’re looking for:

Hi there,

It would be easier to help you if we could see your site code. Please have a look at Requesting Help .