Back to Hugo

collections.Shuffle

docs/content/en/functions/collections/Shuffle.md

0.161.1550 B
Original Source
go-html-template
{{ collections.Shuffle (slice "a" "b" "c") }} → [b a c] 

The result will vary from one build to the next.

To render an unordered list of 5 random pages from a page collection:

go-html-template
<ul>
  {{ $p := site.RegularPages }}
  {{ range $p | collections.Shuffle | first 5 }}
    <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
  {{ end }}
</ul>

{{< new-in 0.149.0 />}}

Using the collections.D function for the same task is significantly faster.