{"id":"bb99b05aad001c64","repo":"gohugoio/hugo","slug":"invalid-intersect-values","errorCode":null,"errorMessage":"invalid intersect values","messagePattern":"invalid intersect values","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/where.go","lineNumber":294,"sourceCode":"\t\tif op == \"not in\" {\n\t\t\treturn !r, nil\n\t\t}\n\t\treturn r, nil\n\tcase \"intersect\":\n\t\tr, err := ns.Intersect(slv, slmv)\n\t\tif err != nil {\n\t\t\treturn false, err\n\t\t}\n\n\t\tif reflect.TypeOf(r).Kind() == reflect.Slice {\n\t\t\ts := reflect.ValueOf(r)\n\n\t\t\tif s.Len() > 0 {\n\t\t\t\treturn true, nil\n\t\t\t}\n\t\t\treturn false, nil\n\t\t}\n\t\treturn false, errors.New(\"invalid intersect values\")\n\tcase \"like\":\n\t\tif svp != nil && smvp != nil {\n\t\t\tre, err := hstrings.GetOrCompileRegexp(*smvp)\n\t\t\tif err != nil {\n\t\t\t\treturn false, err\n\t\t\t}\n\t\t\tif re.MatchString(*svp) {\n\t\t\t\treturn true, nil\n\t\t\t}\n\t\t\treturn false, nil\n\t\t}\n\tdefault:\n\t\treturn false, errors.New(\"no such operator\")\n\t}\n\treturn false, nil\n}\n\nfunc evaluateSubElem(ctx, obj reflect.Value, elemName string) (reflect.Value, error) {","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/collections/where.go#L276-L312","documentation":"With where's \"intersect\" operator, Hugo calls collections.Intersect on the field value and the match value and expects a slice back; the result being non-empty means the condition matches. If Intersect returns a non-slice result (the operands weren't both compatible slices), Hugo reports invalid intersect values.","triggerScenarios":"{{ where $pages \".Params.tags\" \"intersect\" $x }} where the page field or $x is not a slice of comparable basic types — e.g. a scalar string on one side, nil params, or mixed incompatible element types that make Intersect return a non-slice.","commonSituations":"Front matter where tags/categories is authored as a single string instead of a list on some pages; passing a string literal instead of (slice \"a\" \"b\") as the match value; taxonomy params that are maps rather than slices.","solutions":["Ensure both sides are slices: use (slice \"tag1\" \"tag2\") for the match value and list-style front matter (tags: [\"a\"]) on pages.","Audit content files for pages where the param is a scalar string and convert them to lists.","Guard heterogeneous data: filter or normalize the param before using intersect."],"exampleFix":"{{/* before */}}\n{{ $related := where .Site.RegularPages \".Params.tags\" \"intersect\" \"go\" }}\n\n{{/* after */}}\n{{ $related := where .Site.RegularPages \".Params.tags\" \"intersect\" (slice \"go\") }}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"{{ $a := .Params.tags | default slice }}\n{{ $b := site.Params.featuredTags | default slice }}\n{{ if and (reflect.IsSlice $a) (reflect.IsSlice $b) }}\n  {{ $common := intersect $a $b }}\n{{ end }}","tryCatchPattern":null,"preventionTips":["Both intersect arguments must be slices/arrays of comparable elements — default missing params to `slice`","Don't intersect a slice with a string or map; normalize types first","Keep element types homogeneous (all strings or all pages) across both operands"],"tags":["hugo","templates","where","intersect","collections"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}