gohugoio/hugo · error

invalid intersect values

Error message

invalid intersect values

What it means

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.

Source

Thrown at tpl/collections/where.go:294

		if op == "not in" {
			return !r, nil
		}
		return r, nil
	case "intersect":
		r, err := ns.Intersect(slv, slmv)
		if err != nil {
			return false, err
		}

		if reflect.TypeOf(r).Kind() == reflect.Slice {
			s := reflect.ValueOf(r)

			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) {

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Ensure both sides are slices: use (slice "tag1" "tag2") for the match value and list-style front matter (tags: ["a"]) on pages.
  2. Audit content files for pages where the param is a scalar string and convert them to lists.
  3. Guard heterogeneous data: filter or normalize the param before using intersect.

Example fix

{{/* before */}}
{{ $related := where .Site.RegularPages ".Params.tags" "intersect" "go" }}

{{/* after */}}
{{ $related := where .Site.RegularPages ".Params.tags" "intersect" (slice "go") }}
Defensive patterns

Strategy: type-guard

Type guard

{{ $a := .Params.tags | default slice }}
{{ $b := site.Params.featuredTags | default slice }}
{{ if and (reflect.IsSlice $a) (reflect.IsSlice $b) }}
  {{ $common := intersect $a $b }}
{{ end }}

Prevention

When it happens

Trigger: {{ 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.

Common situations: 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.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/bb99b05aad001c64.json. Report an issue: GitHub ↗.