{"id":"e43959e22586e983","repo":"gohugoio/hugo","slug":"grouping-not-supported-for-type-t-t","errorCode":null,"errorMessage":"grouping not supported for type %T %T","messagePattern":"grouping not supported for type %T %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/collections.go","lineNumber":327,"sourceCode":"\n// Group groups a set of items by the given key.\n// This is currently only supported for Pages.\nfunc (ns *Namespace) Group(key any, items any) (any, error) {\n\tif key == nil {\n\t\treturn nil, errors.New(\"nil is not a valid key to group by\")\n\t}\n\n\tif g, ok := items.(collections.Grouper); ok {\n\t\treturn g.Group(key, items)\n\t}\n\n\tin := newSliceElement(items)\n\n\tif g, ok := in.(collections.Grouper); ok {\n\t\treturn g.Group(key, items)\n\t}\n\n\treturn nil, fmt.Errorf(\"grouping not supported for type %T %T\", items, in)\n}\n\n// IsSet returns whether a given array, channel, slice, or map in c has the given key\n// defined.\nfunc (ns *Namespace) IsSet(c any, key any) (bool, error) {\n\tav := reflect.ValueOf(c)\n\tkv := reflect.ValueOf(key)\n\n\tswitch av.Kind() {\n\tcase reflect.Array, reflect.Chan, reflect.Slice:\n\t\tk, err := cast.ToIntE(key)\n\t\tif err != nil {\n\t\t\treturn false, fmt.Errorf(\"isset unable to use key of type %T as index\", key)\n\t\t}\n\t\tif av.Len() > k {\n\t\t\treturn true, nil\n\t\t}\n\tcase reflect.Map:","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/collections/collections.go#L309-L345","documentation":"`group` only works on collections whose element type implements Hugo's internal `collections.Grouper` interface — in practice, only Pages. Hugo tries the collection itself, then a new empty slice of its element type, and if neither is a Grouper it reports both Go types via %T. Grouping arbitrary slices, maps, or strings is unsupported.","triggerScenarios":"`{{ group \"key\" (slice \"a\" \"b\") }}`, `{{ group \"x\" .Params.items }}` (a []any from front matter), or grouping a map — anything that isn't a Pages collection.","commonSituations":"Attempting to use `group` as a generic group-by over data files or params (developers expect SQL-like GROUP BY), or passing `.Data.Terms`/site data instead of Pages. The doc comment states it's currently Pages-only.","solutions":["Only call group on page collections: `{{ $g := group \"featured\" (where .Site.RegularPages \"Params.featured\" true) }}`.","For arbitrary data, build groups manually with a dict: range the items and append each to `$groups` keyed by the field, e.g. via `merge`/`append` on a map of slices.","For taxonomy-style grouping of pages by a field, use Hugo taxonomies or `.Pages.GroupByParam \"field\"` instead."],"exampleFix":"<!-- before -->\n{{ $g := group \"type\" .Site.Data.products.items }}\n<!-- after -->\n{{ $groups := dict }}\n{{ range .Site.Data.products.items }}\n  {{ $k := .type }}\n  {{ $groups = merge $groups (dict $k (append . (index $groups $k | default slice))) }}\n{{ end }}","handlingStrategy":"type-guard","validationCode":"{{/* GroupBy operates on Pages; confirm you have a Pages collection */}}\n{{ with .Pages }}{{ $g := .GroupBy \"Section\" }}{{ end }}","typeGuard":"{{ if eq (printf \"%T\" $coll) \"page.Pages\" }}{{ $g := $coll.GroupBy $field }}{{ end }}","tryCatchPattern":null,"preventionTips":["Call GroupBy/GroupByParam only on Pages collections, not on arbitrary slices or maps","Ensure the field you group by is a supported type (string, int, time) on every page","After `where`/`first` chains, verify the result is still a Pages collection before grouping"],"tags":["hugo","templates","collections","group","pages","type-error"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}