Error when calling GroupBy on non-empty page.Pages

When I try to group a slice of pages by field “”, 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.


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


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 fieldty=string
ERROR Rebuild failed: 
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" "" "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: 
Elem of invalid type page.Page

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

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

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

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

{{ range site.RegularPages.GroupBy "" }}
{{ range site.RegularPages.GroupBy "" }}

Example that demonstrates both restrictions:

git clone --single-branch -b hugo-forum-topic-50217 hugo-forum-topic-50217
cd hugo-forum-topic-50217

Files of interest:

  • layouts/_default/home.html