{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/collections/where.go#L384-L420","documentation":"The `where` function accepts, after the collection and key, either one argument (the match value, implicit equality) or two arguments (operator string + match value). `parseWhereArgs` rejects zero trailing arguments (no match value to compare against) and three or more (too many), via the default branch at where.go:401–402.","triggerScenarios":"Calling `{{ where .Pages \"Title\" }}` (missing match value) or `{{ where .Pages \"Title\" \"eq\" \"x\" \"y\" }}` (three trailing args). The message \"no match argument\" covers the zero-arg case; \"more than or equal to two arguments\" covers three or more.","commonSituations":"A developer omits the match value expecting a truthiness filter, or pastes extra arguments from a multi-condition template expecting AND behavior.","solutions":["Provide exactly one match value: `{{ where .Pages \"Section\" \"blog\" }}`.","Or provide exactly one operator and one match value: `{{ where .Pages \"Section\" \"eq\" \"blog\" }}`.","Chain multiple `where` calls for compound conditions rather than passing extra args."],"exampleFix":"// before\n{{ where .Pages \"Title\" }}\n// after\n{{ where .Pages \"Title\" \"ne\" \"\" }}","handlingStrategy":"validation","validationCode":"// Ensure 1 or 2 trailing args to where\n{{ $trailing := slice $maybeOp $maybeVal }}\n{{ if or (eq (len $trailing) 1) (eq (len $trailing) 2) }}\n  {{ $args := prepend $trailing $key }}\n  {{ where .Pages $key $trailing... }}\n{{ end }}","typeGuard":"func validWhereTrailingArity(n int) bool {\n    return n == 1 || n == 2\n}","tryCatchPattern":null,"preventionTips":["Pass exactly one match value or one operator + one match value.","Chain multiple `where` calls for compound conditions.","Never omit the match value."],"tags":["hugo","template","collections","where","arity"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}