gohugoio/hugo · error
cannot convert type %T to Pages
Error message
cannot convert type %T to Pages
What it means
Thrown by ToPages when the input value matches none of the accepted types (Pages, *Pages, WeightedPages, PageGroup, []Page, or []any of Page). It reports the concrete type so you can see what was passed instead of a page collection.
Solutions
- Pass a Pages collection (or one of the convertible types: WeightedPages, PageGroup, []Page, []any of Page).
- Wrap a single Page in page.Pages{p} before passing.
- For grouped data use ToPagesGroup instead of ToPages.
Example fix
// before
pages, err := page.ToPages(singlePage)
// after
pages, err := page.ToPages(page.Pages{singlePage}) Defensive patterns
Strategy: type-guard
Validate before calling
switch seq.(type) {
case page.Pages, *page.Pages, page.WeightedPages, page.PageGroup, []page.Page, []any:
// convertible
instance:
return fmt.Errorf("not convertible to Pages: %T", seq)
} Type guard
func looksLikePages(seq any) bool {
switch seq.(type) {
case page.Pages, *page.Pages, page.WeightedPages, page.PageGroup, []page.Page, []any:
return true
}
return false
} Try / catch
pages, err := page.ToPages(seq)
if err != nil { /* normalize input or skip */ } Prevention
- Pass only Pages (or convertible) collections to ToPages.
- Wrap single Pages in page.Pages{p}.
- Use ToPagesGroup for grouped data.
When it happens
Trigger: Calling ToPages (often indirectly via the 'pages' template pipe or collections) with a single Page, a string, a map, a PagesGroup, or any non-page slice whose elements are not Page values.
Common situations: Template authors pass a single Page object or a PageGroups slice where a Pages collection is expected; happens with .Related, .Paginator, or sorting helpers.
Related errors
- %T cannot be merged by language
- invalid argument type %T
- invalid slice type %T
- type %T is not a PageGroup
- argument must be a slice
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/23ddfb467b2a5b56.
Report an issue: GitHub.
Appendix: source
Thrown at resources/page/pages.go:87
copy(pages, v)
return pages, nil
case []any:
pages := make(Pages, len(v))
success := true
for i, vv := range v {
p, ok := vv.(Page)
if !ok {
success = false
break
}
pages[i] = p
}
if success {
return pages, nil
}
}
return nil, fmt.Errorf("cannot convert type %T to Pages", seq)
}
// Group groups the pages in in by key.
// This implements collections.Grouper.
func (p Pages) Group(key any, in any) (any, error) {
pages, err := ToPages(in)
if err != nil {
return PageGroup{}, err
}
return PageGroup{Key: key, Pages: pages}, nil
}
// Len returns the number of pages in the list.
func (p Pages) Len() int {
return len(p)
}
// ProbablyEq wraps compare.ProbablyEqerView on GitHub (pinned to 52c9bd7908)