{"id":"71cc09c466dd8743","repo":"gohugoio/hugo","slug":"invalid-argument-type-t","errorCode":null,"errorMessage":"invalid argument type %T","messagePattern":"invalid argument type %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/page/pages_related.go","lineNumber":69,"sourceCode":"}\n\n// Related searches all the configured indices with the search keywords from the\n// supplied document.\nfunc (p Pages) Related(ctx context.Context, optsv any) (Pages, error) {\n\tif len(p) == 0 {\n\t\treturn nil, nil\n\t}\n\n\tvar opts related.SearchOpts\n\tswitch v := optsv.(type) {\n\tcase related.Document:\n\t\topts.Document = v\n\tcase map[string]any:\n\t\tif err := mapstructure.WeakDecode(v, &opts); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"invalid argument type %T\", optsv)\n\t}\n\n\tresult, err := p.search(ctx, opts)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn result, nil\n}\n\n// RelatedIndices searches the given indices with the search keywords from the\n// supplied document.\n// Deprecated: Use Related instead.\nfunc (p Pages) RelatedIndices(ctx context.Context, doc related.Document, indices ...any) (Pages, error) {\n\tindicesStr, err := cast.ToStringSliceE(indices)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/page/pages_related.go#L51-L87","documentation":"Pages.Related accepts either a related.Document (typically a Page) or a map of search options that is weak-decoded into related.SearchOpts. Any other argument type falls through the switch and is rejected with this error, because Hugo cannot infer what to search for.","triggerScenarios":"Calling `.Related` in a template with an argument that is neither a page nor an options map/dict — e.g. `{{ site.RegularPages.Related \"tags\" }}` (a string), a slice, a nil-ish value from a failed lookup, or a taxonomy term object. The %T in the message names the offending Go type.","commonSituations":"Migrating from the deprecated `.RelatedIndices`/`.RelatedTo` calling conventions and passing the old string/keyVals arguments to `.Related`; passing `.Params.something` that isn't a map; forgetting `(dict ...)` around options.","solutions":["Pass the current page: `{{ $related := site.RegularPages.Related . }}`.","For options, pass a dict: `{{ site.RegularPages.Related (dict \"document\" . \"indices\" (slice \"tags\")) }}`.","If you were using `.RelatedIndices . \"tags\"` or `.RelatedTo (keyVals ...)`, either keep those deprecated methods or convert the arguments into the options dict form."],"exampleFix":"<!-- before -->\n{{ $related := site.RegularPages.Related \"tags\" }}\n<!-- after -->\n{{ $related := site.RegularPages.Related (dict \"document\" . \"indices\" (slice \"tags\")) }}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func relatedArg(v any) (any, bool) {\n    switch v.(type) {\n    case page.Page, []page.Page, page.Pages:\n        return v, true\n    default:\n        return nil, false\n    }\n}","tryCatchPattern":"{{ with .Site.RegularPages.Related . }}{{ range . }}...{{ end }}{{ end }}","preventionTips":["Pass the current Page (the `.` context) to .Related, not a string, map, or resource","When using .RelatedTo, build the arg list with `keyVals`, not ad-hoc dicts","Check the type of variables coming from partial params before calling Related"],"tags":["hugo","templates","related-content","type-error"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}