Hi,
I’m trying to display a slice of Page in a very specific order that I build from various front-matter information.
The sort function is way too limited for my need (I would need a user comparison function, but there is no user functions within hugo templates).
Without pagination, I succeed by manually building a (sorted according to my need) slice of pages.
A quick example (my real code is more complex):
{{ $s := .Page.Scratch }}
{{ $s.Set "pages" .Page.Data.Pages }}
{{ $s.Set "default" (slice) }}
{{ $s.Set "cours" (slice) }}
{{ range ($s.Get "pages") }}
{{ $s.Set "type" "default" }}
{{ if findRE "/ue/$" .File.Dir }}
{{ $s.Set "type" "cours" }}
{{ end }}
{{ $s.Set ($s.Get "type") (union ($s.Get ($s.Get "type")) (slice .)) }}
{{ end }}
{{ $s.Set "pages" (union ($s.Get "cours") ($s.Get "default")) }}
Having sorted my pages, I can do
{{ range ($s.Get "pages") }}
...
{{ end }}
However, if I want to add some pagination, it does not work anymore.
If I try:
{{ $paginator := .Page.Paginate (($s.Get "pages")) }}
{{ range $paginator.Pages }}
...
}}
then I get:
[...] at <.Page.Paginate>: error calling Paginate: unsupported type in paginate, got []interface {}
Is it possible to allow Paginate to work from a slice of Page (instead of an internal “Pages” object)? Or is it possible to manually build a “Pages” object?
And same question about a dict of slice of pages that would be accepted by Paginate with the PageGroups function… For now, I get:
[...] at <.Page.Paginate>: error calling Paginate: unsupported type in paginate, got map[string]interface {}
Regards,
Vincent