# RegularPages - can't iterate over nil

**URL:** <https://discourse.gohugo.io/t/regularpages-cant-iterate-over-nil/22269>\
**Category:** support\
**Created:** [December 12, 2019, 4:03am UTC](https://discourse.gohugo.io/t/regularpages-cant-iterate-over-nil/22269 "2019-12-12T04:03:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcurdt](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tcurdt/32/6175_2.png) [@tcurdt](https://discourse.gohugo.io/u/tcurdt)\
**Post date:** [December 12, 2019, 4:03am UTC](https://discourse.gohugo.io/t/regularpages-cant-iterate-over-nil/22269/1 "2019-12-12T04:03:03Z")

</div>

I move this from a template (where it works just fine) into a partial

```
{{ range first 3 (where $.Site.RegularPages "Section" "posts") }}
{{ end }}

```

and it fails with ` error calling where: can't iterate over <nil>`.  
Why is that? I don’t see how the context would matter here.

---

<div class="post-metadata">

**Author:** ![pointyfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pointyfar/32/5797_2.png) [@pointyfar](https://discourse.gohugo.io/u/pointyfar)\
**Post date:** [December 12, 2019, 4:28am UTC](https://discourse.gohugo.io/t/regularpages-cant-iterate-over-nil/22269/2 "2019-12-12T04:28:23Z")

</div>

Do you have a repo that shows this behaviour? I am unable to reproduce your error on a test.

Edit:

Are you passing the “dot” on to the partial call?

I.e.:

```auto
{{ partial "foo.html" . }}

```

---

<div class="post-metadata">

**Author:** ![tcurdt](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tcurdt/32/6175_2.png) [@tcurdt](https://discourse.gohugo.io/u/tcurdt)\
**Post date:** [December 12, 2019, 10:21am UTC](https://discourse.gohugo.io/t/regularpages-cant-iterate-over-nil/22269/3 "2019-12-12T10:21:17Z")

</div>

@pointyfar

That is actually the big change to when it worked before. Because of the problems with relative links (see other thread) I am passing in a dict like this:

```
{{ partial "more.html" (dict "context" . "rel" "rel1") }}

```

but given that

```
{{ range $post := first 10 (where $.Site.RegularPages "Section" "posts") }}
{{ end }}

```

does not depend on `.` but only on `$` I didn’t think that should matter.

I am working on stripped down repo to demonstrate it.

---

<div class="post-metadata">

**Author:** ![tcurdt](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tcurdt/32/6175_2.png) [@tcurdt](https://discourse.gohugo.io/u/tcurdt)\
**Post date:** [December 12, 2019, 10:29am UTC](https://discourse.gohugo.io/t/regularpages-cant-iterate-over-nil/22269/4 "2019-12-12T10:29:13Z")

</div>

Here it is [https://we.tl/t-Hl9LmjsZqm](https://we.tl/t-Hl9LmjsZqm) I run it with `make run`.  
If you go into `./themes/tech/layouts/partials/more.html` and add

```
{{ range $post := first 10 (where $.Site.RegularPages "Section" "posts") }}
{{ end }}

```

You will see the error.

---

<div class="post-metadata">

**Author:** ![pointyfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pointyfar/32/5797_2.png) [@pointyfar](https://discourse.gohugo.io/u/pointyfar)\
**Post date:** [December 12, 2019, 10:59am UTC](https://discourse.gohugo.io/t/regularpages-cant-iterate-over-nil/22269/5 "2019-12-12T10:59:02Z")

</div>

> [@tcurdt](#):
>
> `where $.Site.RegularPages`

Use instead:

```auto
site.RegularPages 
or
$self.Site.RegularPages

```

---

<div class="post-metadata">

**Author:** ![tcurdt](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tcurdt/32/6175_2.png) [@tcurdt](https://discourse.gohugo.io/u/tcurdt)\
**Post date:** [December 12, 2019, 11:38am UTC](https://discourse.gohugo.io/t/regularpages-cant-iterate-over-nil/22269/6 "2019-12-12T11:38:07Z")

</div>

Why does `$self.Site.RegularPages` work but not `$.Site.RegularPages`?  
I thought `$.` should always work.  
And why `site` and not `.Site`?

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![pointyfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pointyfar/32/5797_2.png) [@pointyfar](https://discourse.gohugo.io/u/pointyfar)\
**Post date:** [December 12, 2019, 11:45pm UTC](https://discourse.gohugo.io/t/regularpages-cant-iterate-over-nil/22269/7 "2019-12-12T23:45:27Z")

</div>

From [this bit](https://gohugo.io/templates/introduction/#2-use--to-access-the-global-context) in the docs:

> `$` is set to the starting value of `.` (“the dot”) by default.

My understanding is that when you are then inside a partial, the starting “dot” would be the context passed on to it. So in your case, the `dict`. You can see this by printing `{{$}} / {{.}}` from inside your partial.

`$self.Site...` works because `$self` is a `Page`, and therefore contains the `.Site` variable.

`site....` works because `site` is a global variable, independent of context.

---

<div class="post-metadata">

**Author:** ![tcurdt](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tcurdt/32/6175_2.png) [@tcurdt](https://discourse.gohugo.io/u/tcurdt)\
**Post date:** [December 13, 2019, 10:10am UTC](https://discourse.gohugo.io/t/regularpages-cant-iterate-over-nil/22269/8 "2019-12-13T10:10:01Z")

</div>

Seems like I totally misunderstood `$`. Sounds like it is not global but just per page/template/partial. I don’t find the docs too clear on that. And I didn’t even know there is `site` as global var. Thanks for clearing this up!
