{"record":{"id":"23ddfb467b2a5b56","repo":"gohugoio/hugo","slug":"cannot-convert-type-t-to-pages","errorCode":null,"errorMessage":"cannot convert type %T to Pages","messagePattern":"cannot convert type %T to Pages","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/page/pages.go","lineNumber":87,"sourceCode":"\t\tcopy(pages, v)\n\t\treturn pages, nil\n\tcase []any:\n\t\tpages := make(Pages, len(v))\n\t\tsuccess := true\n\t\tfor i, vv := range v {\n\t\t\tp, ok := vv.(Page)\n\t\t\tif !ok {\n\t\t\t\tsuccess = false\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tpages[i] = p\n\t\t}\n\t\tif success {\n\t\t\treturn pages, nil\n\t\t}\n\t}\n\n\treturn nil, fmt.Errorf(\"cannot convert type %T to Pages\", seq)\n}\n\n// Group groups the pages in in by key.\n// This implements collections.Grouper.\nfunc (p Pages) Group(key any, in any) (any, error) {\n\tpages, err := ToPages(in)\n\tif err != nil {\n\t\treturn PageGroup{}, err\n\t}\n\treturn PageGroup{Key: key, Pages: pages}, nil\n}\n\n// Len returns the number of pages in the list.\nfunc (p Pages) Len() int {\n\treturn len(p)\n}\n\n// ProbablyEq wraps compare.ProbablyEqer","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/page/pages.go#L69-L105","documentation":"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.","triggerScenarios":"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.","commonSituations":"Template authors pass a single Page object or a PageGroups slice where a Pages collection is expected; happens with .Related, .Paginator, or sorting helpers.","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."],"exampleFix":"// before\npages, err := page.ToPages(singlePage)\n// after\npages, err := page.ToPages(page.Pages{singlePage})","handlingStrategy":"type-guard","validationCode":"switch seq.(type) {\ncase page.Pages, *page.Pages, page.WeightedPages, page.PageGroup, []page.Page, []any:\n    // convertible\ninstance:\n    return fmt.Errorf(\"not convertible to Pages: %T\", seq)\n}","typeGuard":"func looksLikePages(seq any) bool {\n    switch seq.(type) {\n    case page.Pages, *page.Pages, page.WeightedPages, page.PageGroup, []page.Page, []any:\n        return true\n    }\n    return false\n}","tryCatchPattern":"pages, err := page.ToPages(seq)\nif err != nil { /* normalize input or skip */ }","preventionTips":["Pass only Pages (or convertible) collections to ToPages.","Wrap single Pages in page.Pages{p}.","Use ToPagesGroup for grouped data."],"tags":["hugo","pages","type-mismatch","templating"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}