Randomized pagination

How do I cause the pages in my paginator to be randomized? I know there’s a shuffle function, but I’m having trouble getting this to work:

{{ range .Paginator.Pages | shuffle }}
       {{ .Render "li" }}
{{ end }}

Full source is here: https://github.com/ccnmtl/digitaltibet/blob/master/layouts/index.html

1 Like


{{ range (.Paginate (.Pages | shuffle)).Pages }}

That gives me this error:

ERROR: 2016/08/03 14:50:23 general.go:212: Error while rendering homepage: template: index.html:6:33: executing “index.html” at <.Pages>: Pages is not a field of struct type *hugolib.Node

{{ range (.Paginate (.Data.Pages | shuffle)).Pages }}

Thanks, but this gives the error:

ERROR: 2016/08/03 15:07:58 general.go:212: Error while rendering homepage: template: index.html:6:22: executing “index.html” at <.Paginate>: error calling Paginate: invoked multiple times with different arguments

You can only have one paginator per node (it is a static site), so you must make sure that there is no previous calls to .Paginate or .Paginator in the template chain for that node.

I see the commit where you added this error here:

But haven’t found any more info on this error. I’m going to try removing this error just to see what happens, out of curiosity.

That sounds fishy. See my comment above. A static site cannot have two different files on the same location on disk.

I do have a call to .Paginate in layouts/_default/list.html, but this error still occurs when I remove that call.

I don’t completely understand this error, but removing that code does allow the pages to be randomized each time I build the site. I was hoping them to be randomized each time the user refreshes the page, but this works until I figure out something better.

I suggest you read a little in the documentation and about Hugo – and understand the concept of static sites.