Excluding current page when using 'shuffle`

This is a bit cleaner, and you will always list 8 pages.

In your original code you would list either 7 or 8, depending on whether the current page is in the first 8 after shuffling.

layouts/_default/single.html
{{ define "main" }}
  <h1>{{ .Title }}</h1>
  {{ .Content }}

  {{ range site.RegularPages | complement (slice .) | shuffle | first 8 }}
    <a href="{{ .RelPermalink }}">{{ .Title }}</a>
  {{ end }}

{{ end }}
2 Likes