{"record":{"id":"a92790a8f810b883","repo":"gohugoio/hugo","slug":"key-is-a-page-method-but-you-can-t-use-it-with-g","errorCode":null,"errorMessage":"{key} is a Page method but you can't use it with GroupBy","messagePattern":"(.+?) is a Page method but you can't use it with GroupBy","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/page/pagegroup.go","lineNumber":130,"sourceCode":"// GroupBy groups by the value in the given field or method name and with the given order.\n// Valid values for order is asc, desc, rev and reverse.\nfunc (p Pages) GroupBy(ctx context.Context, key string, order ...string) (PagesGroup, error) {\n\tif len(p) < 1 {\n\t\treturn nil, nil\n\t}\n\n\tdirection := \"asc\"\n\n\tif len(order) > 0 && (strings.ToLower(order[0]) == \"desc\" || strings.ToLower(order[0]) == \"rev\" || strings.ToLower(order[0]) == \"reverse\") {\n\t\tdirection = \"desc\"\n\t}\n\n\tvar ft any\n\tindex := hreflect.GetMethodIndexByName(pagePtrType, key)\n\tif index != -1 {\n\t\tm := pagePtrType.Method(index)\n\t\tif m.Type.NumOut() == 0 || m.Type.NumOut() > 2 {\n\t\t\treturn nil, errors.New(key + \" is a Page method but you can't use it with GroupBy\")\n\t\t}\n\t\tif m.Type.NumOut() == 1 && m.Type.Out(0).Implements(errorType) {\n\t\t\treturn nil, errors.New(key + \" is a Page method but you can't use it with GroupBy\")\n\t\t}\n\t\tif m.Type.NumOut() == 2 && !m.Type.Out(1).Implements(errorType) {\n\t\t\treturn nil, errors.New(key + \" is a Page method but you can't use it with GroupBy\")\n\t\t}\n\t\tft = m\n\t} else {\n\t\tvar ok bool\n\t\tft, ok = pagePtrType.Elem().FieldByName(key)\n\t\tif !ok {\n\t\t\treturn nil, errors.New(key + \" is neither a field nor a method of Page\")\n\t\t}\n\t}\n\n\tvar tmp reflect.Value\n\tswitch e := ft.(type) {","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/page/pagegroup.go#L112-L148","documentation":"`Pages.GroupBy` reflects the named Page method to group by it. It requires the method to return a usable group key: either a single non-error value, or (value, error). The first guard (pagegroup.go:129-130) rejects methods that return zero values or more than two values, since there is no groupable key to extract.","triggerScenarios":"Calling `{{ .Pages.GroupBy \"SomeMethod\" }}` where `SomeMethod` has a signature with no return values or more than two return values (e.g. a void setter method or a multi-tuple method).","commonSituations":"Grouping by a method not designed for grouping (a configurator/mutator); guessing a method name that resolves to an internal helper; version upgrades that change a method's arity.","solutions":["Group by a method that returns a single comparable value (e.g. \"Section\", \"Type\", \"Date\").","Verify the method's return signature in the Hugo Page API docs before using it as a GroupBy key.","If you need custom grouping logic, add the value as a page param and group by that param name."],"exampleFix":"{{/* before: method returns nothing usable */}}\n{{ .Pages.GroupBy \"SomeVoidMethod\" }}\n\n{{/* after: group by a real scalar-returning method */}}\n{{ .Pages.GroupBy \"Section\" }}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only group by methods returning one comparable value or (value, error).","Check the Page method's return arity before grouping."],"tags":["hugo","templates","groupby","reflection"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}