{"id":"4f612ad86f4fd301","repo":"gohugoio/hugo","slug":"type-t-is-not-a-weightedpage","errorCode":null,"errorMessage":"type %T is not a WeightedPage","messagePattern":"type %T is not a WeightedPage","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/page/weighted.go","lineNumber":77,"sourceCode":"\treturn WeightedPage{Weight: weight, Page: p, owner: owner}\n}\n\nfunc (w WeightedPage) String() string {\n\treturn fmt.Sprintf(\"WeightedPage(%d,%q)\", w.Weight, w.Page.Title())\n}\n\n// Slice is for internal use.\n// for the template functions. See collections.Slice.\nfunc (p WeightedPage) Slice(in any) (any, error) {\n\tswitch items := in.(type) {\n\tcase WeightedPages:\n\t\treturn items, nil\n\tcase []any:\n\t\tweighted := make(WeightedPages, len(items))\n\t\tfor i, v := range items {\n\t\t\tg, ok := v.(WeightedPage)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"type %T is not a WeightedPage\", v)\n\t\t\t}\n\t\t\tweighted[i] = g\n\t\t}\n\t\treturn weighted, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"invalid slice type %T\", items)\n\t}\n}\n\n// Pages returns the Pages in this weighted page set.\nfunc (wp WeightedPages) Pages() Pages {\n\tpages := make(Pages, len(wp))\n\tfor i := range wp {\n\t\tpages[i] = wp[i].Page\n\t}\n\treturn pages\n}\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/page/weighted.go#L59-L95","documentation":"WeightedPage.Slice implements Hugo's internal collections.Slice contract: when slicing a []any it requires every element to be a WeightedPage so it can build a homogeneous WeightedPages collection. If any element is a different type (e.g. a plain Page, a string, a map), the conversion fails with this error rather than silently producing a mixed collection.","triggerScenarios":"Using the `slice` template function (or first/last/after and friends that re-slice) on a mix where the first element is a WeightedPage (typically from .Site.Taxonomies weighted lists) but later elements are plain Pages or other values, e.g. {{ $s := slice $weightedPage $regularPage }}.","commonSituations":"Templates that merge taxonomy term pages (WeightedPages) with regular .Pages collections; appending arbitrary values to a weighted list obtained from .Site.Taxonomies.tags; refactors that switch from .Pages to taxonomy .WeightedPages without updating downstream slice building.","solutions":["Convert weighted pages to plain pages first with .Pages before combining: {{ $all := union $terms.Pages .Site.RegularPages }}.","Keep collections homogeneous: only slice WeightedPage values together, or only Page values together.","If you need the underlying page from a WeightedPage, use its .Page field before slicing."],"exampleFix":"<!-- before -->\n{{ $s := slice $weighted $somePage }}\n<!-- after: normalize to Pages first -->\n{{ $s := slice $weighted.Page $somePage }}","handlingStrategy":"type-guard","validationCode":"{{/* only weight-sort actual pages */}}\n{{ $pages := where .Site.RegularPages \"Weight\" \"gt\" 0 }}","typeGuard":"// In Go extensions: p, ok := v.(page.WeightedPage); if !ok { /* skip */ }\n// In templates: {{ if reflect.IsMap . | not }}...{{ end }} — pass Pages, not arbitrary slices","tryCatchPattern":null,"preventionTips":["Pass only Pages/WeightedPages collections to weighted operations (e.g. taxonomy .Pages)","Don't mix arbitrary dicts/slices into page collections before sorting by weight","When ranging taxonomies, use .WeightedPages accessors rather than rebuilding slices"],"tags":["templates","type-mismatch","taxonomy","hugo"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}