# Help debugging resource usage

**URL:** <https://discourse.gohugo.io/t/help-debugging-resource-usage/30392>\
**Category:** support\
**Created:** [January 4, 2021, 12:16pm UTC](https://discourse.gohugo.io/t/help-debugging-resource-usage/30392 "2021-01-04T12:16:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhby](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mhby/32/9047_2.png) [@mhby](https://discourse.gohugo.io/u/mhby)\
**Post date:** [January 4, 2021, 12:16pm UTC](https://discourse.gohugo.io/t/help-debugging-resource-usage/30392/1 "2021-01-04T12:16:54Z")

</div>

I need to get an image within a Page bundle from a template (index.html) and I am having a hard time debugging the situation, could someone check if my reasoning is correct ?

In index.html  
`{{- $image := (.Site.GetPage "/blog/interview-john").Resources.GetMatch "john-avatar.jpg" -}}`  
`{{- $image := $image.Resize "x100 q75 jpg" -}}`

This give me an error  
```` Failed to render pages: render of "home" failed: "/Users/matthieu/apps/www.pilot.pm/layouts/index.html:198:56": execute of template failed: template: index.html:198:56: executing "main" at <$image.Resize>: nil pointer evaluating resource.Resource.Resize`

So to debug I set this  
` {{ printf "%#v" $image }}`

Which gave me this inforamtion, which is an adress to a resource (am I right ?)  
`&resources.resourceAdapter .... .....`

Now that I am sure $image is a resource I should be able to call .resize isn’t it ?

What am I missing ?

Thanks

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [January 4, 2021, 12:28pm UTC](https://discourse.gohugo.io/t/help-debugging-resource-usage/30392/2 "2021-01-04T12:28:46Z")

</div>

> [@mhby](#):
>
> What am I missing ?

You need to _first_ use `.GetPage` to get the relevant Page, _then_ within its context fetch its `.Resources` like so:

> [@Accessing page resources by name?](https://discourse.gohugo.io/t/accessing-page-resources-by-name/15228/2):
>
> ```auto
> {{ with .Site.GetPage "accreditations/index.md" }}
> $resources := .Resources
> ...
> 
> {{ $img := $resources.Match (.image) }}
> 
> ```

---

<div class="post-metadata">

**Author:** ![mhby](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mhby/32/9047_2.png) [@mhby](https://discourse.gohugo.io/u/mhby)\
**Post date:** [January 4, 2021, 12:32pm UTC](https://discourse.gohugo.io/t/help-debugging-resource-usage/30392/3 "2021-01-04T12:32:05Z")

</div>

You are perfectly right, I though i was okay with my `(.Site.GetPage "/blog/interview-john").Resources [..] `

Thanks you

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [January 4, 2021, 12:34pm UTC](https://discourse.gohugo.io/t/help-debugging-resource-usage/30392/4 "2021-01-04T12:34:07Z")

</div>

> [@mhby](#):
>
> `{{- $image := ... -}}`  
> `{{- $image := ... -}}`

Apart from that, it’s wrong (people with deeper knowledge correct me if I am wrong) to “assign” a variable twice. You use `:=` to create a variable and then must use `=` to change it’s value/content.

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [January 4, 2021, 12:39pm UTC](https://discourse.gohugo.io/t/help-debugging-resource-usage/30392/5 "2021-01-04T12:39:31Z")

</div>

> [@mhby](#):
>
> I though i was okay with my `(.Site.GetPage "/blog/interview-john").Resources [..] `

@mhby  
The above construct does not work because although you are using `.GetPage` to fetch that Page, you are not getting its resources because you are not within the Page context.

> [@davidsneighbour](#):
>
> “assign” a variable twice. You use `:=` to create a variable and then must use `=` to change it’s value/content.

@davidsneighbour  
Yes, you have a point about variable overwrites. It is always better to overwrite than re-assign the same variable However as far as I know re-assigning with `:=` instead of overwriting with `=` shouldn’t cause a problem (unless we are talking about some huge project -then I don’t know-).

---

<div class="post-metadata">

**Author:** ![mhby](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mhby/32/9047_2.png) [@mhby](https://discourse.gohugo.io/u/mhby)\
**Post date:** [January 4, 2021, 12:44pm UTC](https://discourse.gohugo.io/t/help-debugging-resource-usage/30392/6 "2021-01-04T12:44:41Z")

</div>

@alexandros  
Thanks for the precision, it makes sense now.

@davidsneighbour  
You are 100% right and within pure Go it should have throw en error (I make that mistake all the time)

---

<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:** [January 6, 2021, 12:44pm UTC](https://discourse.gohugo.io/t/help-debugging-resource-usage/30392/7 "2021-01-06T12:44:48Z")

</div>

Closed on January 6, 2021, 12:44pm UTC

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