# Change COLLECTION in range based on page kind

**URL:** <https://discourse.gohugo.io/t/change-collection-in-range-based-on-page-kind/36240>\
**Category:** support\
**Created:** [December 27, 2021, 4:24pm UTC](https://discourse.gohugo.io/t/change-collection-in-range-based-on-page-kind/36240 "2021-12-27T16:24:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tucker\_Higley](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tucker_higley/32/15399_2.png) [@Tucker\_Higley](https://discourse.gohugo.io/u/Tucker_Higley)\
**Post date:** [December 27, 2021, 4:24pm UTC](https://discourse.gohugo.io/t/change-collection-in-range-based-on-page-kind/36240/1 "2021-12-27T16:24:45Z")

</div>

How do I go about changing the collection within a range based on the page type? I’ve tried using scratch but I can never seem to get the scratch syntax to work. I’m still trying to wrap by head around how variables work within scopes for Hugo. Any help would be appreciated, I’ve tried some other methods on the forms but cant seems to figure it out. Thank you

```auto
{{if eq .Kind "home"}}
  {{$collection := .Site.Pages}}
{{else}}
  {{$collection := .Pages}}
{{end}}

{{range $collection}}

{{end}}

```

---

<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:** [December 27, 2021, 4:32pm UTC](https://discourse.gohugo.io/t/change-collection-in-range-based-on-page-kind/36240/2 "2021-12-27T16:32:06Z")

</div>

Initialize ( := ) outside the block, and assign ( = ) within.

```auto
{{ $var := 0 }}
{{ if true }}
  {{ $var = 1 }}
{{ else }}
  {{ $var = 2 }}
{{ end }}

```
