{"id":"a5662a04b60c87b4","repo":"gohugoio/hugo","slug":"can-t-evaluate-the-array-by-no-match-argument-or-m","errorCode":null,"errorMessage":"can't evaluate the array by no match argument or more than or equal to two arguments","messagePattern":"can't evaluate the array by no match argument or more than or equal to two arguments","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/where.go","lineNumber":402,"sourceCode":"\treturn zero, fmt.Errorf(\"%s is neither a struct field, a method nor a map element of type %s\", elemName, typ)\n}\n\n// parseWhereArgs parses the end arguments to the where function.  Return a\n// match value and an operator, if one is defined.\nfunc parseWhereArgs(args ...any) (mv reflect.Value, op string, err error) {\n\tswitch len(args) {\n\tcase 1:\n\t\tmv = reflect.ValueOf(args[0])\n\tcase 2:\n\t\tvar ok bool\n\t\tif op, ok = args[0].(string); !ok {\n\t\t\terr = errors.New(\"operator argument must be string type\")\n\t\t\treturn\n\t\t}\n\t\top = strings.TrimSpace(strings.ToLower(op))\n\t\tmv = reflect.ValueOf(args[1])\n\tdefault:\n\t\terr = errors.New(\"can't evaluate the array by no match argument or more than or equal to two arguments\")\n\t}\n\treturn\n}\n\n// elemResolver resolves a sub-element from a reflect.Value.\n// Built once before the loop to avoid repeated type checks and reflect.ValueOf allocations.\ntype elemResolver func(reflect.Value) (reflect.Value, error)\n\n// newElemResolver returns a resolver optimized for the given element type and path.\n// Returns nil if optimization isn't possible, in which case the caller should\n// fall back to evaluateSubElem.\nfunc (ns *Namespace) newElemResolver(ctxv reflect.Value, elemType reflect.Type, path []string) elemResolver {\n\tif elemType.Kind() == reflect.Interface {\n\t\tif len(path) != 1 {\n\t\t\treturn nil\n\t\t}\n\t\treturn ns.newInterfaceMethodResolver(ctxv, elemType, path[0])\n\t}","sourceCodeStart":384,"sourceCodeEnd":420,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/collections/where.go#L384-L420","documentation":"parseWhereArgs hit its default case: after the collection and key, `where` accepts either one argument (a match value) or two (operator + match value). Zero trailing args or three-plus is unparseable, so Hugo refuses to evaluate the filter. The message wording is awkward but means 'wrong number of arguments'.","triggerScenarios":"Calling `where` with only a collection and key (`where .Site.Pages \"Section\"`), or with extra arguments (`where .Pages \"Section\" \"eq\" \"blog\" \"extra\"`), often from a piped expression injecting an extra arg.","commonSituations":"Forgetting the match value; piping into where (`$x | where \"k\" \"v1\" \"v2\"` adds the piped value as a final arg); copy-paste leaving stray arguments.","solutions":["Provide exactly one match value: `where .Site.Pages \"Section\" \"blog\"`.","For an operator form, use exactly operator + value: `where .Pages \"Params.n\" \">\" 3`.","When piping, remember the piped value becomes the last argument — restructure the call accordingly."],"exampleFix":"<!-- before -->\n{{ range where .Site.RegularPages \"Section\" }}\n<!-- after -->\n{{ range where .Site.RegularPages \"Section\" \"blog\" }}","handlingStrategy":"validation","validationCode":"{{/* call where with exactly 3 or 4 args */}}\n{{ $r := where $pages \"Section\" \"blog\" }}\n{{ $r2 := where $pages \"Params.year\" \">=\" 2024 }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["where takes (collection, key, match) or (collection, key, operator, match) — never fewer or more","When piping, remember the piped value becomes the last argument; count total args","Don't pass a slice of match values without the \"in\" operator form"],"tags":["hugo","templates","where","arguments"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}