# Error calling where: can't iterate over nil in Partial

**URL:** <https://discourse.gohugo.io/t/error-calling-where-cant-iterate-over-nil-in-partial/45149>\
**Category:** support\
**Created:** [July 4, 2023, 6:27pm UTC](https://discourse.gohugo.io/t/error-calling-where-cant-iterate-over-nil-in-partial/45149 "2023-07-04T18:27:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sids](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@Sids](https://discourse.gohugo.io/u/Sids)\
**Post date:** [July 4, 2023, 6:27pm UTC](https://discourse.gohugo.io/t/error-calling-where-cant-iterate-over-nil-in-partial/45149/1 "2023-07-04T18:27:12Z")

</div>

Hello all.

I have been trying to use Partials to generate some data from my files.

Here is the call to the partial -  
` {{ partial "print_topLevel.html" (dict "context" . "secName" "00_dept_a" "codeID" "00-dept-01") }}`

and here is the partial stored in (/layouts/partials/print\_topLevel.html) file.

```auto
<!--Testing if parameters are actually being passed -->
{{ $secName := .secName }}
{{ $codeID := .codeID }}
{{ $secName }}<br>
{{ $codeID }}<br>
<!-- Above works Good -->

<!--Fetch the MD file from the $secName folder for the specified code_ID in $codeID-->
{{ $topLevel := where (where .site.Pages "Section" $secName) "context.Code_ID" "eq" $codeID }}
<!--Display the Contents / Front Matter of this 0=.md file-->
{{- range $topLevel -}}

    <h1>{{ .context.ID_Name }}</h1>
    <p><strong>Code ID:</strong> {{.context.Code_ID }}</p>
    <p><strong>Full Name:</strong> {{.context.fullName }}</p>

{{- end -}}

```

I have also tried using the $.Site.Pages, $.context.Site.Pages and $.content.site.Pages but it has failed on all counts.  
With the above I am getting the error -

```auto
execute of template failed at <where .site.Pages "Section" $secName>: error calling where: can’t iterate over <nil> 

```

Any ideas how I can fix this partial so that it would work good for the data that I have?

Thank you for your time to read out and trying to help.

Warm regards,  
Sids.

---

<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:** [July 4, 2023, 7:07pm UTC](https://discourse.gohugo.io/t/error-calling-where-cant-iterate-over-nil-in-partial/45149/2 "2023-07-04T19:07:59Z")

</div>

> [@Sids](#):
>
> `.site.Pages`

site.RegularPages – no leading dot

---

<div class="post-metadata">

**Author:** ![Sids](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@Sids](https://discourse.gohugo.io/u/Sids)\
**Post date:** [July 4, 2023, 9:42pm UTC](https://discourse.gohugo.io/t/error-calling-where-cant-iterate-over-nil-in-partial/45149/3 "2023-07-04T21:42:03Z")

</div>

Sir, thank you once again, you have been a life saver for me.

A couple of things -  
I read that we could use the global site variable. So I experimented with site.Pages (as you could see my last code that I placed on the thread). Any specific reasons why I should be using the .RegularPages here and not .Pages?

Also on another note, after I changed to site.RegularPages, the code still gave me error -

```auto
 <.context.Code_ID>: can't evaluate field context in type page.Page

```

So I changed it to .Params.Code\_ID etc and it worked fine.

the “context” in the dictionary was set to the . during the call. So shouldn’t have this worked?

Thanks again sir for being there. I dont know about others, but personally, I feel indebted to you because on 99% of my problems, you have been the one who has showed me a way out and helped me learn some as well.

Regards,  
Sid.

---

<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:** [July 4, 2023, 10:08pm UTC](https://discourse.gohugo.io/t/error-calling-where-cant-iterate-over-nil-in-partial/45149/4 "2023-07-04T22:08:53Z")

</div>

> [@Sids](#):
>
> So shouldn’t have this worked?

No. The full descriptor is `.Page.Params.Code_ID`. You passed the `.Page` part of it, so you need to provide the rest (i.e., `.Params.Code_ID`).

> [@Sids](#):
>
> So I experimented with site.Pages

With this content structure:

```plaintext
content/
├── books/
│ ├── book-1.md
│ └── book-2.md
└── _index.md

```

This:

```plaintext
{{ range site.Pages }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}

```

Produces this:

```plaintext
Book 2
Books
mystery
Tags
Book 1
fiction
Home
Categories

```

While this:

```plaintext
{{ range site.RegularPages }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}

```

Produces this:

```plaintext
Book 2
Book 1

```

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [July 11, 2023, 6:40pm UTC](https://discourse.gohugo.io/t/error-calling-where-cant-iterate-over-nil-in-partial/45149/5 "2023-07-11T18:40:35Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
