juh2
November 12, 2016, 6:10pm
1
<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 }}
juh2
November 13, 2016, 9:31am
3
This gives me a
error calling first: can't iterate over hugolib.Taxonomy
bep
November 13, 2016, 10:18am
4
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.