# Where "not in" with empty slice

**URL:** https://discourse.gohugo.io/t/where-not-in-with-empty-slice/54409
**Category:** support
**Created:** [April 16, 2025, 5:10pm UTC](https://discourse.gohugo.io/t/where-not-in-with-empty-slice/54409 "2025-04-16T17:10:46Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![AlanBreck](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/alanbreck/32/11694_2.png) [@AlanBreck](https://discourse.gohugo.io/u/AlanBreck)
#### Post date: [April 16, 2025, 5:10pm UTC](https://discourse.gohugo.io/t/where-not-in-with-empty-slice/54409/1 "2025-04-16T17:10:46Z")

</div>

Is the following behavior expected?

Non-empty slice

```auto
{{- $pages := where site.RegularPages "Lang" "not in" (slice "fr") -}}
{{ printf "#%v" $pages }} --> Pages(1)

```

Empty slice

```auto
{{- $pages := where site.RegularPages "Lang" "not in" (slice) -}}
{{ printf "#%v" $pages }} --> Pages(0)

```

Demo: [GitHub - AlanBreck/hugo-testing at not-in-behavior](https://github.com/AlanBreck/hugo-testing/tree/not-in-behavior)

The actual scenario is that I have a JSON data file which can potentially be an empty array. I would have expected both of the above examples to result in 1 page since the page language is not found in an empty slice.

---

<div class="post-metadata">

### Author: ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)
#### Post date: [April 16, 2025, 5:15pm UTC](https://discourse.gohugo.io/t/where-not-in-with-empty-slice/54409/2 "2025-04-16T17:15:47Z")

</div>

If this is multilingual site, then this doesn’t make any sense.

```plaintext
where site.RegularPages "Lang" "not in" (slice "fr")

```

`site.RegularPages` refers to the current site (language). Conceptually its easier to think of projects and sites. A monolingual project has one site. A multilingual project has two or more sites.

If you want to access all pages across all sites, use [`site.AllPages`](https://gohugo.io/methods/site/allpages/).

---

<div class="post-metadata">

### Author: ![AlanBreck](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/alanbreck/32/11694_2.png) [@AlanBreck](https://discourse.gohugo.io/u/AlanBreck)
#### Post date: [April 16, 2025, 5:21pm UTC](https://discourse.gohugo.io/t/where-not-in-with-empty-slice/54409/3 "2025-04-16T17:21:51Z")

</div>

Understood. Primarily asking about the behavior of the `not in` operator. The same behavior can be observed if checking `Kind`:

Non-empty slice

```auto
{{- $pages := where site.RegularPages "Kind" "not in" (slice "section") -}}
{{ printf "#%v" $pages }} --> Pages(1)

```

Empty slice

```auto
{{- $pages := where site.RegularPages "Kind" "not in" (slice) -}}
{{ printf "#%v" $pages }} --> Pages(0)

```

---

<div class="post-metadata">

### Author: ![AlanBreck](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/alanbreck/32/11694_2.png) [@AlanBreck](https://discourse.gohugo.io/u/AlanBreck)
#### Post date: [April 16, 2025, 7:25pm UTC](https://discourse.gohugo.io/t/where-not-in-with-empty-slice/54409/4 "2025-04-16T19:25:12Z")

</div>

Noting that `collections.In` with an empty slice yields (to my mind) the expected behavior:

```auto
{{ printf "%#v" (not (in $forbiddenFruits "pineapple")) }} --> true
{{ printf "%#v" (not (in $forbiddenFruits "apple")) }} --> false
{{ printf "%#v" (not (in slice "pineapple")) }} --> true 

```

---

<div class="post-metadata">

### Author: ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)
#### Post date: [April 16, 2025, 11:02pm UTC](https://discourse.gohugo.io/t/where-not-in-with-empty-slice/54409/5 "2025-04-16T23:02:15Z")

</div>

I agree with you.

```plaintext
content/
├── posts/
│ ├── _index.md
│ └── post-1.md
└── _index.md

```

```plaintext
{{ $p := where site.RegularPages "Kind" "not in" slice }}
{{ $p.Len | warnf "%#[2]v (%[2]T) [%[1]d]" math.Counter }} → 0 (expected 1) 

{{ $n := not (in (slice) "a") }}
{{ $n | warnf "%#[2]v (%[2]T) [%[1]d]" math.Counter }} → true (expected true)

```

Go ahead a log an issue and reference this topic.

---

<div class="post-metadata">

### Author: ![AlanBreck](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/alanbreck/32/11694_2.png) [@AlanBreck](https://discourse.gohugo.io/u/AlanBreck)
#### Post date: [April 17, 2025, 7:02pm UTC](https://discourse.gohugo.io/t/where-not-in-with-empty-slice/54409/6 "2025-04-17T19:02:14Z")

</div>

Submitted here: [Unexpected behavior of "where ... not in" with empty slice · Issue #13621 · gohugoio/hugo · GitHub](https://github.com/gohugoio/hugo/issues/13621)

Thanks!
