Slicing keys and values

    <ul class="list-unstyled">
    {{ $baseurl := .Site.BaseURL }}
    {{ range $key, $value := .Site.Taxonomies.categories }}
    <li><a href="{{ $baseurl}}categories/{{ $key | urlize}}">{{ $key }}</a> ({{ len $value }})
    </li>
    {{ end }}
    </ul>

This works fine. Now I want to range only the first 4 key-value pairs.

The simple

    {{ range first 4 ($key, $value := .Site.Taxonomies.categories) }}

does not work.

You have to filter the list first over that you would like to range.

{{ range $key, $value := first 4 .Site.Taxonomies.categories }}

This gives me a

error calling first: can't iterate over hugolib.Taxonomy

first etc. with a map isn’t supported – and since a map isn’t ordered it first 4 would not make sense. I have no workaround for you, maybe others wil chime in.