Error when calling GroupBy on non-empty page.Pages

When I try to group a slice of pages by field “Params.paige.pin”, I get an error that doesn’t make sense to me. It seems to be complaining that the element type of page.Pages is Page.

Code:

{{ warnf "%v matches={%v} matchesty=%T field=%v fieldty=%T" time.Now.UnixNano (debug.Dump $matches) $matches $field $field}}
{{ $matchgroups := $matches.GroupBy $field }}

Output:

WARN  1717907409157755000 matches={[
  {
    "Date": "2023-10-03T18:12:15-07:00",
    "Lastmod": "2023-10-03T18:12:15-07:00",
    "PublishDate": "0001-01-01T00:00:00Z",
    "ExpiryDate": "0001-01-01T00:00:00Z",
    "Aliases": null,
    "BundleType": "branch",
    "Description": "",
    "Draft": false,
    "IsHome": false,
    "Keywords": null,
    "Kind": "taxonomy",
    "Layout": "paige/cloud",
    "LinkTitle": "Categories",
    "IsNode": true,
    "IsPage": false,
    "Path": "/categories",
    "Slug": "",
    "Lang": "en",
    "IsSection": false,
    "Section": "categories",
    "Sitemap": {
      "ChangeFreq": "",
      "Priority": -1,
      "Filename": "sitemap.xml",
      "Disable": false
    },
    "Type": "categories",
    "Weight": 10
  }
]} matchesty=page.Pages field=Params.paige.pin fieldty=string
ERROR Rebuild failed: 
render: 
failed to render pages: 
render of "home" failed: "/Users/will/Developer/paige/layouts/_default/list.html:5:3": 
execute of template failed at <partial "paige/pages.html" $page>: 
error calling partial: 
execute of template failed at <partial "paige/group.html" (dict "groups" (slice (dict "field" "Params.paige.pin" "operator" "eq" "value" true)) "pages" $collections)>: "/Users/will/Developer/paige/layouts/partials/paige/group.html:27:31": 
execute of template failed at <$matches.GroupBy>: 
error calling GroupBy: 
reflect: 
Elem of invalid type page.Page

I haven’t looked into the details, but the above caught my attention.

https://github.com/gohugoio/hugo/issues/12289

If you can’t do this because of the issue above…

{{ range site.RegularPages.GroupByParam "paige.pin" }}

…then it seems like you shouldn’t be able to do these either:

{{ range site.RegularPages.GroupBy "Params.paige.pin" }}
{{ range site.RegularPages.GroupBy "Params.foo" }}

Example that demonstrates both restrictions:

git clone --single-branch -b hugo-forum-topic-50217 https://github.com/jmooring/hugo-testing hugo-forum-topic-50217
cd hugo-forum-topic-50217
hugo 

Files of interest:

  • layouts/_default/home.html