{"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/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/page/pagegroup.go#L375-L411","documentation":"Returned by PageGroup.Slice when converting a []any into a PagesGroup for the template `slice`/collections functions: every element must be a PageGroup, and one element is some other type. Hugo fails fast rather than silently dropping the mismatched element.","triggerScenarios":"Template code building a slice that mixes PageGroup values with other types, e.g. `{{ $g := slice (index $groups 0) .Site.Params.foo }}` or appending a Page/string into a slice whose first element is a PageGroup, then passing it where a PagesGroup is expected.","commonSituations":"Custom templates combining results of .GroupBy/.GroupByDate with plain pages or strings, iterating grouped output and rebuilding slices incorrectly, or partials that receive heterogeneous data.","solutions":["Ensure every element of the slice is a PageGroup — don't mix Pages, strings, or maps with grouped results","Use the output of .GroupBy* directly instead of rebuilding it with slice/append","If you need pages, use .Pages of each group rather than the groups themselves"],"exampleFix":"// before\n{{ $mixed := slice (index $groups 0) .Site.RegularPages }}\n// after\n{{ $onlyGroups := slice (index $groups 0) (index $groups 1) }}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"{{ $isPageGroup := and (reflect.IsMap . | not) (isset . \"Key\") (isset . \"Pages\") }}","tryCatchPattern":null,"preventionTips":["Only pass the result of .GroupBy/.GroupByDate/.GroupByParam (a PageGroups value) to functions expecting PageGroup","Don't mix plain page slices and grouped results in the same template variable","When paginating groups, pass the whole PageGroups result to .Paginate, not individual elements you constructed yourself"],"tags":["hugo","templates","type-error","page-groups"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}