gohugoio/hugo · error
unsupported type in paginate from slice, got %T instead of P
Error message
unsupported type in paginate from slice, got %T instead of PageGroup
What it means
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.
Source
Thrown at resources/page/pagegroup.go:453
case nil:
return nil, true, nil
case PagesGroup:
return v, true, nil
case []PageGroup:
return PagesGroup(v), true, nil
case []any:
l := len(v)
if l == 0 {
break
}
switch v[0].(type) {
case PageGroup:
pagesGroup := make(PagesGroup, l)
for i, ipg := range v {
if pg, ok := ipg.(PageGroup); ok {
pagesGroup[i] = pg
} else {
return nil, false, fmt.Errorf("unsupported type in paginate from slice, got %T instead of PageGroup", ipg)
}
}
return pagesGroup, true, nil
}
}
return nil, false, nil
}
View on GitHub ↗ (pinned to 8a468df065)
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
Example fix
// before
{{ $pag := .Paginate (slice (index $groups 0) .Site.RegularPages) }}
// after
{{ $pag := .Paginate (.Pages.GroupByDate "2006") }} Defensive patterns
Strategy: type-guard
Validate before calling
{{ $grouped := .Pages.GroupByDate "2006" }}{{ $pag := .Paginate $grouped }} Type guard
// only slices whose elements are PageGroup are valid: use output of GroupBy* directly, never a hand-built slice
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- arguments to symdiff must be slices or arrays
- can't iterate over %T
- text must be a string
- first argument must be a map
- type %T not supported
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/b14e852efa3289ce.json.
Report an issue: GitHub ↗.