"error calling Paginate: cannot convert type page.PagesGroup to Pages"

I’m trying to list “pinned” and “unpinned” pages in a Hugo section separately:

{{ range (where $page.Pages "Params.paige.pin" true).ByPublishDate.Reverse }}
    {{ partial "paige/page.html" . }}
{{ end }}
{{ $ps1 := $page.Pages }}
{{ $pgs := $ps1.ByPublishDate.Reverse.GroupByPublishDate "January 2006" }}
{{ $p := $page.Paginate $pgs }}
{{ range $p.PageGroups }}
    <p class="h5 paige-date-header text-center">{{ .Key }}</p>
    {{ range .Pages }}
        {{ partial "paige/page.html" . }}
    {{ end }}
{{ end }}

This works with 5 pages (1 pinned) and paginate: 10 in config.yaml.

However, the second list has pinned posts in it. When I try to filter them out (see $ps2 line)

{{ range (where $page.Pages "Params.paige.pin" true).ByPublishDate.Reverse }}
    {{ partial "paige/page.html" . }}
{{ end }}
{{ $ps2 := where $page.Pages "Params.paige.pin" "ne" true }}
{{ $pgs := $ps2.ByPublishDate.Reverse.GroupByPublishDate "January 2006" }}
{{ $p := $page.Paginate $pgs }}
{{ range $p.PageGroups }}
    <p class="h5 paige-date-header text-center">{{ .Key }}</p>
    {{ range .Pages }}
        {{ partial "paige/page.html" . }}
    {{ end }}
{{ end }}

this also works.

However, if I set paginate: 1 in config.yaml, I get an error:

❯ hugo server --themesDir ../.. --enableGitInfo
Start building sites … 
hugo v0.111.1+extended darwin/amd64 BuildDate=unknown
Error: Error building site: failed to render pages: render of "term" failed: "/Users/Will/Developer/paige/layouts/_default/term.html:5:3": execute of template failed: template: _default/term.html:5:3: executing "main" at <partial "paige/pages.html" $page>: error calling partial: "/Users/Will/Developer/paige/layouts/partials/paige/pages.html:26:26": execute of template failed: template: partials/paige/pages.html:26:26: executing "partials/paige/pages.html" at <$page.Paginate>: error calling Paginate: cannot convert type page.PagesGroup to Pages
Built in 336 ms

OK, let’s set paginate: 10 again. But we still get the error:

❯ hugo server --themesDir ../.. --enableGitInfo
Start building sites … 
hugo v0.111.1+extended darwin/amd64 BuildDate=unknown
Error: Error building site: failed to render pages: render of "term" failed: "/Users/Will/Developer/paige/layouts/_default/term.html:5:3": execute of template failed: template: _default/term.html:5:3: executing "main" at <partial "paige/pages.html" $page>: error calling partial: "/Users/Will/Developer/paige/layouts/partials/paige/pages.html:26:26": execute of template failed: template: partials/paige/pages.html:26:26: executing "partials/paige/pages.html" at <$page.Paginate>: error calling Paginate: cannot convert type page.PagesGroup to Pages
Built in 292 ms

How about if we delete resources and public?

~/Developer/paige/exampleSite master* ⇡
❯ rm -rf resources public

~/Developer/paige/exampleSite master* ⇡
❯ hugo server --themesDir ../.. --enableGitInfo
Start building sites … 
hugo v0.111.1+extended darwin/amd64 BuildDate=unknown
Error: Error building site: failed to render pages: render of "term" failed: "/Users/Will/Developer/paige/layouts/_default/term.html:5:3": execute of template failed: template: _default/term.html:5:3: executing "main" at <partial "paige/pages.html" $page>: error calling partial: "/Users/Will/Developer/paige/layouts/partials/paige/pages.html:26:26": execute of template failed: template: partials/paige/pages.html:26:26: executing "partials/paige/pages.html" at <$page.Paginate>: error calling Paginate: cannot convert type page.PagesGroup to Pages
Built in 3299 ms

Still get the error.

What if we change back to $ps1?

{{ range (where $page.Pages "Params.paige.pin" true).ByPublishDate.Reverse }}
    {{ partial "paige/page.html" . }}
{{ end }}
{{ $ps1 := $page.Pages }}
{{ $pgs := $ps1.ByPublishDate.Reverse.GroupByPublishDate "January 2006" }}
{{ $p := $page.Paginate $pgs }}
{{ range $p.PageGroups }}
    <p class="h5 paige-date-header text-center">{{ .Key }}</p>
    {{ range .Pages }}
        {{ partial "paige/page.html" . }}
    {{ end }}
{{ end }}

Now there’s no error.

What’s going on? What does “error calling Paginate: cannot convert type page.PagesGroup to Pages” mean? Why is that a problem when I filter pages with where, but not a problem if I don’t? And why does the pagination limit in config.yaml affect this?

Edit: Code at GitHub - willfaught/paige at pin (last commit).

Maybe “complement” could simplify some of the collection creation.
complement | Hugo (gohugo.io)

Thanks, that worked!

1 Like

It looks like it works for paginating the “unpinned” pages with a normal paginate setting, but if I set the site “paginate” parameter to be less than the total number of pages (e.g. 1), then I get the same error:

failed to render pages: render of "term" failed:
"/Users/Will/Developer/paige/layouts/_default/term.html:5:3":
execute of template failed at <partial "paige/pages.html" $page>:
error calling partial:
"/Users/Will/Developer/paige/layouts/partials/paige/pages.html:29:30":
execute of template failed at <$page.Paginate>:
error calling Paginate:
cannot convert type page.PagesGroup to Pages 

The current code in pages.html:

{{ $pinned := where $page.Pages "Params.paige.pin" true }}

{{ range $pinned.ByPublishDate.Reverse }}
    {{ partial "paige/page.html" . }}
{{ end }}

{{ $unpinned := complement $pinned $page.Pages }}
{{ $pagegroups := $unpinned.ByPublishDate.Reverse.GroupByPublishDate "January 2006" }}
{{ $pager := $page.Paginate $pagegroups }}

{{ range $pager.PageGroups }}
    <p class="h5 paige-date-header text-center">{{ .Key }}</p>

    {{ range .Pages }}
        {{ partial "paige/page.html" . }}
    {{ end }}
{{ end }}

Line 29:

{{ $pager := $page.Paginate $pagegroups }}

Edit: If there are no pinned pages, then setting paginate to 1 doesn’t cause an error.

See the full code.

So, I have looked at the source code for Paginate, and it wrongly returns an error when passed an empty PageGroup (it just moves on and checks if if is of type Pages, which it is not). This is a bug, and I will fix it.

You can work around it by something like this:

{{ $unpinned := complement $pinned $page.Pages }}
{{ if $unpinned }}
{{ $pagegroups := $unpinned.ByPublishDate.Reverse.GroupByPublishDate "January 2006" }}
{{ $pager := $page.Paginate $pagegroups }}
{{ end }}

@bep Thanks for looking into this!

I don’t follow how an empty PageGroup is happening. With 4 (unpinned) pages, and paginate:1, there should be 4 PageGroups, each with 1 Page, correct?

Would your fix also allow pagination of Pages filtered with the where func?

You can work around it by something like this:

{{ $unpinned := complement $pinned $page.Pages }}
{{ if $unpinned }}
{{ $pagegroups := $unpinned.ByPublishDate.Reverse.GroupByPublishDate “January 2006” }}
{{ $pager := $page.Paginate $pagegroups }}
{{ end }}

Do you mean this?

{{ $unpinned := complement $pinned $page.Pages }}

{{ if $unpinned }}
    {{ $pagegroups := $unpinned.ByPublishDate.Reverse.GroupByPublishDate "January 2006" }}
    {{ $pager := $page.Paginate $pagegroups }}

    {{ range $pager.PageGroups }}
        <p class="h5 paige-date-header text-center">{{ .Key }}</p>

        {{ range .Pages }}
            {{ partial "paige/page.html" . }}
        {{ end }}
    {{ end }}
{{ end }}

There are 4 unpinned pages, so $unpinned is always truthy.

@bep I think there’s a second bug here. When I do:

{{ $pinned := where $page.Pages "Params.paige.pin" true }}

{{ range $pinned.ByPublishDate.Reverse }}
    {{ partial "paige/page.html" . }}
{{ end }}

{{ $unpinned := complement $pinned $page.Pages }}
{{ $pagegroups := $unpinned.ByPublishDate.Reverse.GroupByPublishDate "January 2006" }}
{{ warnf "@@@@@@@@@@@@@ time=%v title=%v up=%v p=%v pgs=%v" now.UnixNano ($page.Title) (len $unpinned) (len $pinned) (len $pagegroups) }}
{{ $pager := $page.Paginate $pagegroups }}

{{ range $pager.PageGroups }}
    {{ warnf "!!!!!!!!!!!! time=%v p=%v" now.UnixNano (len .Pages) }}
    <p class="h5 paige-date-header text-center">{{ .Key }}</p>

    {{ range .Pages }}
        {{ partial "paige/page.html" . }}
    {{ end }}
{{ end }}

and change paginate to 3, I get that error:

failed to render pages: render of "term" failed:
"/Users/Will/Developer/paige/layouts/_default/term.html:5:3":
execute of template failed at <partial "paige/pages.html" $page>:
error calling partial:
"/Users/Will/Developer/paige/layouts/partials/paige/pages.html:30:30":
execute of template failed at <$page.Paginate>:
error calling Paginate:
cannot convert type page.PagesGroup to Pages 

If I alter what warnf prints slightly, then there’s no error.

If I change paginate to 2, the error happens again.

If I alter what warnf prints slightly again, then there’s no error.

I can keep doing this over and over.

The output of those warnfs:

Change of config file detected, rebuilding site.
2023-03-08 21:24:36.339 -0800
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476791372000 title=Content up=4 p=1 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476791424000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476794412000 title=Customization up=2 p=0 pgs=2
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476794450000 p=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476794771000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476795494000 title=Layouts up=2 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476795582000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476798624000 title=Content up=4 p=1 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476798678000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476800915000 title=Shortcodes up=7 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476800964000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476804886000 title=Shortcodes up=7 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476804923000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476805273000 title=content up=4 p=1 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476805312000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476805775000 title=customization up=3 p=0 pgs=3
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476805810000 p=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476806112000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476809201000 title=Shortcodes up=7 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476809238000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476809442000 title=content up=4 p=1 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476809472000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476809738000 title=customization up=3 p=0 pgs=3
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476809807000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476813343000 title=layouts up=2 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476813383000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476813932000 title=paige up=16 p=1 pgs=4
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476813973000 p=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476814647000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476817177000 title=shortcodes up=7 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476817271000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476820198000 title=paige up=16 p=1 pgs=4
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476820230000 p=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476820512000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476821512000 title=shortcodes up=7 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476821546000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476824356000 title=paige up=16 p=1 pgs=4
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476824390000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476825452000 title=shortcodes up=7 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476825541000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476828624000 title=paige up=16 p=1 pgs=4
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476828664000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476833412000 title=paige up=16 p=1 pgs=4
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476833451000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476838718000 title=paige up=16 p=1 pgs=4
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476838756000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476843412000 title=paige up=16 p=1 pgs=4
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476843454000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476943120000 title=Shortcodes up=7 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476943163000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476943696000 title=shortcodes up=7 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476943725000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476943753000 title=paige up=16 p=1 pgs=4
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476943782000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476951584000 title=code up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476951635000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476953340000 title=emoji up=0 p=1 pgs=0
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476953727000 title=css up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476953761000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476955037000 title=gallery up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476955071000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476955094000 title=home up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476955124000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476956913000 title=html up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476956952000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476957559000 title=figures up=5 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476957598000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476958332000 title=images up=2 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476958367000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476959406000 title=katex up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476959435000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476960175000 title=markdown up=2 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476960207000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476961224000 title=figures up=5 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476961255000 p=2
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476961847000 title=math up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476961875000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476962527000 title=privacy up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476962556000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476963657000 title=quotations up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476963685000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476964847000 title=figures up=5 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476964873000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476964917000 title=search up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476965144000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476965599000 title=sections up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476965635000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476966715000 title=shortcodes up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476966750000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476972373000 title=show up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476972416000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476972523000 title=singles up=2 p=0 pgs=2
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476972554000 p=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476972852000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476973012000 title=style up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476973041000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476973733000 title=text up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476973763000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476976001000 title=typesetting up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476976036000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476976145000 title=videos up=2 p=0 pgs=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476976160000 title=vimeo up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476976176000 p=2
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476976188000 p=1
WARN 2023/03/08 21:24:36 @@@@@@@@@@@@@@ time=1678339476976888000 title=youtube up=1 p=0 pgs=1
WARN 2023/03/08 21:24:36 !!!!!!!!!!!!! time=1678339476976923000 p=1
ERROR 2023/03/08 21:24:36 failed to render pages: render of "term" failed: "/Users/Will/Developer/paige/layouts/_default/term.html:5:3": execute of template failed: template: _default/term.html:5:3: executing "main" at <partial "paige/pages.html" $page>: error calling partial: "/Users/Will/Developer/paige/layouts/partials/paige/pages.html:30:30": execute of template failed: template: partials/paige/pages.html:30:30: executing "partials/paige/pages.html" at <$page.Paginate>: error calling Paginate: cannot convert type page.PagesGroup to Pages
Rebuilt in 639 ms

There’s no empty list of PageGroups, and no empty list of Pages per PageGroup.

As I said, the only explanation I have for the above error (and the bug in the code, which I have fixed, is pretty obvious when I look at it now) is that .Paginate is called with an empty page.PagesGroup.

@bep Can you link to the commit? I don’t see it in master. I’d like to test with it.

Have a look here:

1 Like

Confirmed that 0.111.3 fixed the issue. Thanks @bep!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.