{"id":"b14e852efa3289ce","repo":"gohugoio/hugo","slug":"unsupported-type-in-paginate-from-slice-got-t-in","errorCode":null,"errorMessage":"unsupported type in paginate from slice, got %T instead of PageGroup","messagePattern":"unsupported type in paginate from slice, got %T instead of PageGroup","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/page/pagegroup.go","lineNumber":453,"sourceCode":"\tcase nil:\n\t\treturn nil, true, nil\n\tcase PagesGroup:\n\t\treturn v, true, nil\n\tcase []PageGroup:\n\t\treturn PagesGroup(v), true, nil\n\tcase []any:\n\t\tl := len(v)\n\t\tif l == 0 {\n\t\t\tbreak\n\t\t}\n\t\tswitch v[0].(type) {\n\t\tcase PageGroup:\n\t\t\tpagesGroup := make(PagesGroup, l)\n\t\t\tfor i, ipg := range v {\n\t\t\t\tif pg, ok := ipg.(PageGroup); ok {\n\t\t\t\t\tpagesGroup[i] = pg\n\t\t\t\t} else {\n\t\t\t\t\treturn nil, false, fmt.Errorf(\"unsupported type in paginate from slice, got %T instead of PageGroup\", ipg)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn pagesGroup, true, nil\n\t\t}\n\t}\n\n\treturn nil, false, nil\n}\n","sourceCodeStart":435,"sourceCodeEnd":462,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/page/pagegroup.go#L435-L462","documentation":"Returned by ToPagesGroup when a []any passed to .Paginate starts with a PageGroup (so Hugo commits to treating it as grouped pages) but a later element is a different type. Grouped pagination requires a homogeneous slice of PageGroup values.","triggerScenarios":"Calling `.Paginate` with a hand-built slice whose first element is a PageGroup but later elements are Pages, maps, or strings, e.g. `{{ .Paginate (slice $group1 $somePage) }}` — element 0 passes the type switch, element N fails the per-element assertion.","commonSituations":"Templates that append extra items to the result of .Pages.GroupBy before paginating, merging grouped and ungrouped collections, or theme code using `append`/`slice` on grouped data incorrectly.","solutions":["Pass the GroupBy result directly to .Paginate: `{{ $p := .Paginate (.Pages.GroupByDate \"2006\") }}`","If mixing data, paginate plain Pages instead and group inside the pager loop","Check any append/slice manipulation for elements that are not PageGroup"],"exampleFix":"// before\n{{ $pag := .Paginate (slice (index $groups 0) .Site.RegularPages) }}\n// after\n{{ $pag := .Paginate (.Pages.GroupByDate \"2006\") }}","handlingStrategy":"type-guard","validationCode":"{{ $grouped := .Pages.GroupByDate \"2006\" }}{{ $pag := .Paginate $grouped }}","typeGuard":"// only slices whose elements are PageGroup are valid: use output of GroupBy* directly, never a hand-built slice","tryCatchPattern":null,"preventionTips":["Pass either a Pages collection or the direct result of a GroupBy* method to .Paginate — never a heterogeneous or manually assembled slice","Avoid transforming grouped results with slice/append/where in ways that change element types before paginating","Keep the GroupBy call adjacent to the Paginate call in the template so the type is obvious"],"tags":["hugo","pagination","templates","type-error"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}