gohugoio/hugo · error

no such operator

Error message

no such operator

What it means

In `where`, the operator (when provided) must be one of the supported set: `=`, `==`, `eq`, `!=`, `<>`, `ne`, `>=`, `ge`, `>`, `gt`, `<=`, `le`, `<`, `lt`, `in`, `not in`, `intersect`, `like`. The `checkCondition` switch has a `default` branch at where.go:306–307 that fires for any unrecognized operator string.

Solutions

  1. Use only the supported operators listed in the Hugo docs.
  2. For substring/regex matching use `like` (regex), not `matches` or `contains`.
  3. For membership use `in` or `not in`.

Example fix

// before
{{ where .Pages "Title" "contains" "Hugo" }}
// after
{{ where .Pages "Title" "like" "Hugo" }}
Defensive patterns

Strategy: validation

Validate before calling

{{ $validOps := slice "eq" "ne" "gt" "gte" "lt" "lte" "in" "not in" "like" "intersect" }}
{{ if in $validOps $op }}
  {{ where .Pages "Title" $op $val }}
{{ end }}

Type guard

func isValidWhereOp(op string) bool {
    valid := []string{"","=","==","eq","!=","<>","ne",">=","ge",">","gt","<=","le","<","lt","in","not in","intersect","like"}
    for _, v := range valid { if v == op { return true } }
    return false
}

Prevention

When it happens

Trigger: Passing an unsupported operator string: `{{ where .Pages "Date" "matches" "2024" }}` (use `like` for regex), or a typo like `{{ where .Pages "Section" "equels" "blog" }}`.

Common situations: A developer assumes SQL-style operators (`matches`, `contains`, `is`) or mistypes a valid operator. Also common when migrating from another template language's syntax.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/972d28e7e8d65610. Report an issue: GitHub.

Appendix: source

Thrown at tpl/collections/where.go:307

			if s.Len() > 0 {
				return true, nil
			}
			return false, nil
		}
		return false, errors.New("invalid intersect values")
	case "like":
		if svp != nil && smvp != nil {
			re, err := hstrings.GetOrCompileRegexp(*smvp)
			if err != nil {
				return false, err
			}
			if re.MatchString(*svp) {
				return true, nil
			}
			return false, nil
		}
	default:
		return false, errors.New("no such operator")
	}
	return false, nil
}

func evaluateSubElem(ctx, obj reflect.Value, elemName string) (reflect.Value, error) {
	if !obj.IsValid() {
		return zero, errors.New("can't evaluate an invalid value")
	}

	typ := obj.Type()
	obj, isNil := hreflect.Indirect(obj)

	// first, check whether obj has a method. In this case, obj is
	// a struct or its pointer. If obj is a struct,
	// to check all T and *T method, use obj pointer type Value
	objPtr := obj
	if !hreflect.IsInterfaceOrPointer(objPtr.Kind()) && objPtr.CanAddr() {
		objPtr = objPtr.Addr()

View on GitHub (pinned to 52c9bd7908)