# \[Solved\] Problem with "where in" construct

**URL:** <https://discourse.gohugo.io/t/solved-problem-with-where-in-construct/7315>\
**Category:** support\
**Created:** [July 5, 2017, 4:42pm UTC](https://discourse.gohugo.io/t/solved-problem-with-where-in-construct/7315 "2017-07-05T16:42:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leo](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@leo](https://discourse.gohugo.io/u/leo)\
**Post date:** [July 5, 2017, 4:42pm UTC](https://discourse.gohugo.io/t/solved-problem-with-where-in-construct/7315/1 "2017-07-05T16:42:12Z")

</div>

Hello!

I want to paginate over a list of files in a certain subdirectory.  
This is what I am trying to do:

`{{ range $index, $element := (where (where .Data.Pages "Type" "eq" "guideline") ".File.Dir" "in" "/text/" ) }}`

It should give me a list of guidelines stored in the “text” directory.  
However, nothing is returned.

When I try this (including the full path), the files are returned as expected:

`{{ range $index, $element := (where (where .Data.Pages "Type" "eq" "guideline") ".File.Dir" "in" "guidelines/EN/text/" ) }}`

Am I using the “in” function wrong or is it broken and does not recognize substrings anymore?

I already tried what was recommended in [this](https://discourse.gohugo.io/t/paginate-with-where-in-syntax-help/3967/2) thread, but it didn’t help sadly.

Cheers,

Leo

---

<div class="post-metadata">

**Author:** ![nordictiger](https://avatars.discourse-cdn.com/v4/letter/n/85f322/32.png) [@nordictiger](https://discourse.gohugo.io/u/nordictiger)\
**Post date:** [July 5, 2017, 9:49pm UTC](https://discourse.gohugo.io/t/solved-problem-with-where-in-construct/7315/2 "2017-07-05T21:49:04Z")

</div>

Hi Leo,

Looks like `in` can be used in two different context. First, as operator in where condition. In this context it checks if left argument exists in array on the right, so you could use it like following.

`where .Data.Pages ".File.Dir" "in" (slice "guidelines/EN/text/" "guidelines/DE/text/")`

Second scenario is logical function comparing substrings `(in "big main string" "substring")`

I’m not sure if `where` can be convinced somehow to use logical functions but even if it can’t there is easy workaround.

```
{{ range $index, $element := where .Data.Pages "Type" "eq" "guideline" }}
    {{ if (in $element.File.Dir "/text/") }}
        Do your magic stuff here
    {{end}}
{{end}}

```

Best Regards,  
Tarmo

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [July 5, 2017, 9:58pm UTC](https://discourse.gohugo.io/t/solved-problem-with-where-in-construct/7315/3 "2017-07-05T21:58:15Z")

</div>

> [@nordictiger](#):
>
> I’m not sure if where can be convinced somehow to use logical functions but even if it can’t there is easy workaround.

> <https://github.com/gohugoio/hugo/pull/3673>
>
> This enables \`AND\` (\`intersect\`) and \`OR\` (\`union\`) filters when combined with… \`where\`.
> 
> Example:
> 
> \`\`\`go
> {{ $pages := where .Site.RegularPages "Type" "not in" (slice "page" "about") }}
> {{ $pages := $pages | union (where .Site.RegularPages "Params.pinned" true) }}
> {{ $pages := $pages | intersect (where .Site.RegularPages "Params.images" "!=" nil) }}
> \`\`\`
> 
> The above fetches regular pages not of \`page\` or \`about\` type unless they are pinned. And finally, we exclude all pages with no \`images\` set in Page params.
> 
> Fixes #3174

---

<div class="post-metadata">

**Author:** ![leo](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@leo](https://discourse.gohugo.io/u/leo)\
**Post date:** [July 6, 2017, 12:00pm UTC](https://discourse.gohugo.io/t/solved-problem-with-where-in-construct/7315/4 "2017-07-06T12:00:37Z")

</div>

Hey Tarmo, thanks for your reply,  
yes, you are right in this special case the condition within the range would work, I am gonna use that.  
In other cases that I need to handle though, the condition needs to be within the range itself. To be more specific: when working with the paginator I can’t have the if, because that might render empty pages.

@bep  
Thank you for your reply, I am looking forward to v0.25 then to make it proper.
