{"record":{"id":"34b2904ed9795158","repo":"gohugoio/hugo","slug":"type-t-is-not-a-pagegroup","errorCode":null,"errorMessage":"type %T is not a PageGroup","messagePattern":"type %T is not a PageGroup","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/page/pagegroup.go","lineNumber":393,"sourceCode":"\tif p.Key != otherP.Key {\n\t\treturn false\n\t}\n\n\treturn p.Pages.ProbablyEq(otherP.Pages)\n}\n\n// Slice is for internal use.\n// for the template functions. See collections.Slice.\nfunc (p PageGroup) Slice(in any) (any, error) {\n\tswitch items := in.(type) {\n\tcase PageGroup:\n\t\treturn items, nil\n\tcase []any:\n\t\tgroups := make(PagesGroup, len(items))\n\t\tfor i, v := range items {\n\t\t\tg, ok := v.(PageGroup)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"type %T is not a PageGroup\", v)\n\t\t\t}\n\t\t\tgroups[i] = g\n\t\t}\n\t\treturn groups, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"invalid slice type %T\", items)\n\t}\n}\n\n// Len returns the number of pages in the page group.\nfunc (psg PagesGroup) Len() int {\n\tl := 0\n\tfor _, pg := range psg {\n\t\tl += len(pg.Pages)\n\t}\n\treturn l\n}\n","sourceCodeStart":375,"sourceCodeEnd":411,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/page/pagegroup.go#L375-L411","documentation":"Returned by PageGroup.Slice when iterating a []any slice and encountering an element that is not of type PageGroup. The %T verb substitutes the actual Go type of the offending element. This is an internal method used by template functions to construct a PagesGroup from heterogeneous input.","triggerScenarios":"Calling .Slice on a PageGroup or passing a []any containing mixed types (some PageGroup, some not) to a template function that expects a PagesGroup. This typically happens in Go code or advanced templates that manually assemble page groups.","commonSituations":"A custom template or Go integration that builds a slice of mixed page groups and plain pages; accidentally passing Pages instead of PagesGroup to a grouping function; a template partial that receives unexpected types from a poorly typed data pipeline.","solutions":["Ensure every element in the []any slice passed to PageGroup.Slice is actually a PageGroup value — the error message names the offending type via %T.","Use the Hugo group function (e.g. .Pages.GroupBy) which returns properly typed PagesGroup, instead of manually constructing the slice.","Add a Go type assertion before calling Slice if you are building the slice programmatically."],"exampleFix":"// before — mixed types in the slice\ngroups := []any{pg1, somePage, pg2}\nresult, err := pageGroup.Slice(groups)\n// error: type page.Page is not a PageGroup\n\n// after — all elements are PageGroup\nresult, err := pageGroup.Slice([]any{pg1, pg2})\n\n// or use the template-level GroupBy which returns PagesGroup directly:\n{{ range .Pages.GroupBy \"Section\" }}\n  {{ .Key }}: {{ .Pages }}\n{{ end }}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Type guard for PageGroup elements before calling Slice\nfunc isPageGroup(v any) bool {\n    _, ok := v.(PageGroup)\n    return ok\n}\n\n// Filter a heterogeneous slice to only PageGroup values\nfunc filterPageGroups(items []any) []PageGroup {\n    var groups []PageGroup\n    for _, v := range items {\n        if pg, ok := v.(PageGroup); ok {\n            groups = append(groups, pg)\n        }\n    }\n    return groups\n}","tryCatchPattern":"// Guard the Slice call with a pre-check\nvar valid []any\nfor _, v := range items {\n    if _, ok := v.(PageGroup); !ok {\n        return nil, fmt.Errorf(\"element of type %T is not a PageGroup\", v)\n    }\n    valid = append(valid, v)\n}\nreturn pageGroup.Slice(valid)","preventionTips":["Prefer Hugo's built-in GroupBy template methods which return properly typed PagesGroup.","Type-assert every element before building a []any for PageGroup.Slice.","Avoid mixing Pages and PagesGroup in the same data pipeline — they are different types."],"tags":["hugo","pages","pagegroup","type-mismatch","templates"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}