{"record":{"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":"exception","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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/collections/collections.go#L309-L345","documentation":"Returned by the collections.Group template function when neither items nor its slice element implements collections.Grouper. Group first checks items for the Grouper interface, then newSliceElement(items); if both fail it errors with %T %T showing the outer and element types. Grouping is currently only supported for Pages (and types implementing Grouper).","triggerScenarios":"Calling `group key items` in a template where items is not a Pages collection or a type that implements Grouper — e.g. a slice of plain maps, strings, or a single Page. The function requires a collection whose element type knows how to group itself.","commonSituations":"Trying to group a slice of dict/strings, grouping a single object instead of .Pages, or grouping a custom data list that doesn't implement the Grouper interface.","solutions":["Pass a Pages collection (e.g. `.Site.RegularPages`) to group; that is the supported input.","For non-page data, pre-group in your template using `slice`/`range`/a partial instead of the `group` function.","If grouping a custom type, implement the collections.Grouper interface on its slice element so Group can dispatch to it."],"exampleFix":"// before\n{{ $groups := group \"date\" .Params.posts }}\n\n// after\n{{ $groups := group \"date\" .Site.RegularPages }}","handlingStrategy":"type-guard","validationCode":"// Guard that items implements Grouper (Pages do) before grouping.\nfunc isGrouper(v any) bool {\n    _, ok1 := v.(collections.Grouper)\n    if ok1 { return true }\n    // also check slice element\n    rv := reflect.ValueOf(v)\n    if rv.Kind() == reflect.Slice && rv.Len() > 0 {\n        _, ok2 := rv.Index(0).Interface().(collections.Grouper)\n        return ok2\n    }\n    return false\n}","typeGuard":"// Go type guard for Grouper interface.\nfunc asGrouper(v any) (collections.Grouper, bool) {\n    g, ok := v.(collections.Grouper)\n    return g, ok\n}","tryCatchPattern":null,"preventionTips":["Only call group on Pages collections (e.g. .Site.RegularPages).","For custom data, group manually with range/slice instead of the group function.","Implement Grouper on custom collection element types if you need group support."],"tags":["collections","group","template","type-mismatch","pages"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}