# .Scratch within partial range

**URL:** <https://discourse.gohugo.io/t/scratch-within-partial-range/12700>\
**Category:** support\
**Created:** [July 2, 2018, 2:40pm UTC](https://discourse.gohugo.io/t/scratch-within-partial-range/12700 "2018-07-02T14:40:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbozzay](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bbozzay/32/6412_2.png) [@bbozzay](https://discourse.gohugo.io/u/bbozzay)\
**Post date:** [July 2, 2018, 2:40pm UTC](https://discourse.gohugo.io/t/scratch-within-partial-range/12700/1 "2018-07-02T14:40:55Z")

</div>

I’m trying to use .Scratch in a range within a partial file. The goal is to set a .Scratch value outside of the range, change the scratch value in the range, then display the new value outside of the range. However, I can’t seem to even display the existing scratch value in the range.

In my main file, I’m using dict to pass context:

```
{{ partial "sections/build.html" (dict "c" . "g" $ ) }}`

```

In my partial file I’m able to set a scratch and display it properly. However, this doesn’t work within the range.

```
<!--. is .c-->
<!--$ is .g-->

{{ .g.Scratch.Set "number" "seven" }}

<!--displays seven correctly-->
{{ .g.Scratch.Get "number" }}
          
    {{ range .c.row1 }}
    <!--doesn't return anything-->
        {{ .g.Scratch.Get "number" }}
    {{ end }}

```

I know that I could set a variable equal to the scratch value and then display my scratch within the range this way. However, then I can’t reference the new scratch value outside of the range.

---

<div class="post-metadata">

**Author:** ![regis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/regis/32/4958_2.png) [@regis](https://discourse.gohugo.io/u/regis)\
**Post date:** [July 2, 2018, 6:28pm UTC](https://discourse.gohugo.io/t/scratch-within-partial-range/12700/2 "2018-07-02T18:28:28Z")

</div>

> [@bbozzay](#):
>
> However, then I can’t reference the new scratch value outside of the range.

I would store your `.g.Scratch` in a variable instead. I did not test this, but I’m pretty sure, it would be accessible later on.

```auto
{{ $scratch := .g.Scratch }}
{{ $scratch.Set "number" "seven" }}
{{ range .c.row1 }}
    {{ $scratch.Get "number" }}
 {{ end }}

```

---

<div class="post-metadata">

**Author:** ![bbozzay](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bbozzay/32/6412_2.png) [@bbozzay](https://discourse.gohugo.io/u/bbozzay)\
**Post date:** [July 2, 2018, 6:54pm UTC](https://discourse.gohugo.io/t/scratch-within-partial-range/12700/3 "2018-07-02T18:54:57Z")

</div>

You solved my problem, thank you!

I was previously creating the variable like this:

```
{{ .g.Scratch.Set "number" "seven" }}
{{ $number := .g.Scratch.Get "number" }}
```

---

<div class="post-metadata">

**Author:** ![regis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/regis/32/4958_2.png) [@regis](https://discourse.gohugo.io/u/regis)\
**Post date:** [July 3, 2018, 12:26am UTC](https://discourse.gohugo.io/t/scratch-within-partial-range/12700/4 "2018-07-03T00:26:50Z")

</div>

Glad I could help! 🙂  
FIY: You can now mark your issue as “solved” by clicking the three little dots below the comment which solved it and clicking the checkbox. This way the thread is marked as solved!
