{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/page/weighted.go#L59-L95","documentation":"Returned by `WeightedPage.Slice` when it is asked to convert a `[]any` whose elements are not all `WeightedPage` values. Slice is the internal adapter used by the `collections.Slice` template function and by `apply`-style template plumbing. The element-level type check at weighted.go:75-78 fires when a heterogeneous slice is passed in.","triggerScenarios":"A template calls a slice/apply helper over a list that mixes `WeightedPage` with other types (Pages, ints, strings), e.g. `apply (seq 5) \"weightedPageSlice\"`. Most commonly hit via `collections.Slice` invoked with mixed element types where a WeightedPages result was expected.","commonSituations":"Custom taxonomy templates that pipe a blend of `.Pages` and `.Data.Terms` into a weighted-page construct; partial templates reused across contexts where the param is sometimes a Page; upgrading Hugo where `apply` semantics tightened.","solutions":["Filter the input slice so every element is a `WeightedPage` before calling the slice helper.","Use `.Pages` or `.Data.Terms` directly instead of routing through `collections.Slice` for weighted pages.","Build the WeightedPages slice in Go/template via `index .Site.Taxonomies` rather than assembling it element-by-element."],"exampleFix":"// template -- before\n{{ $mixed := slice .Page (site.Taxonomies.tags.first) }}\n{{ $wp := apply $mixed \"slice\" }}\n\n// after\n{{ $wp := .Site.Taxonomies.tags }}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// In templates, narrow before passing to weighted-page helpers.\n// Go-side:\nfunc isWeightedPage(v any) bool {\n\t_, ok := v.(page.WeightedPage)\n\treturn ok\n}","tryCatchPattern":"// In Go template code, filter first:\n{{ $wp := slice }}\n{{ range where $input \"weightedPage\" true }}{{ $wp = $wp | append . }}{{ end }}","preventionTips":["Don't mix element types in slices passed to `collections.Slice`.","Prefer built-in `.Site.Taxonomies` collections over hand-built lists.","Keep taxonomy templates single-type."],"tags":["templates","weighted-page","collections","type-mismatch"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}