# Page Resource access through variable

**URL:** <https://discourse.gohugo.io/t/page-resource-access-through-variable/27279>\
**Category:** support\
**Created:** [July 31, 2020, 12:34pm UTC](https://discourse.gohugo.io/t/page-resource-access-through-variable/27279 "2020-07-31T12:34:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![koni](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/koni/32/12029_2.png) [@koni](https://discourse.gohugo.io/u/koni)\
**Post date:** [July 31, 2020, 12:34pm UTC](https://discourse.gohugo.io/t/page-resource-access-through-variable/27279/1 "2020-07-31T12:34:29Z")

</div>

Hi there,

I am getting some troubles to access a page resource.  
In my frontmatter, I defined a ressource called cover as follow

```
[[resources]]
  name = "cover"
  src = "discover.jpg"
  title = "my cover title"

```

In my template, following code works perfectly :

```
{{ with .Resources.GetMatch "cover" }}
    {{ .RelPermalink }}
{{ end }}

```

However this code is not working and I do not understand why

```
{{ $image:= (.Resources.GetMatch "cover") }}
{{ $image.RelPermalink }}

```

Here is the error I get :  
`execute of template failed: template: blog/single.html:33:17: executing "main" at <$image.RelPermalink>: nil pointer evaluating resource.Resource.RelPermalink`

I am using Hugo v0.74.3/extended.

Is there an explanation for this ?

---

<div class="post-metadata">

**Author:** ![pamubay](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pamubay/32/17838_2.png) [@pamubay](https://discourse.gohugo.io/u/pamubay)\
**Post date:** [July 31, 2020, 1:07pm UTC](https://discourse.gohugo.io/t/page-resource-access-through-variable/27279/2 "2020-07-31T13:07:40Z")

</div>

because there is a page that doesnt have the “cover” resources.

the first method using `with` works, because `with` literally translate to `IF THIS EXISTS THEN DO THIS`

> **[Introduction to Hugo Templating](https://gohugo.io/templates/introduction/#example-1-with)**
>
> Hugo uses Go's \`html/template\` and \`text/template\` libraries as the basis for the templating.

---

<div class="post-metadata">

**Author:** ![koni](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/koni/32/12029_2.png) [@koni](https://discourse.gohugo.io/u/koni)\
**Post date:** [July 31, 2020, 1:16pm UTC](https://discourse.gohugo.io/t/page-resource-access-through-variable/27279/3 "2020-07-31T13:16:21Z")

</div>

Thanks a lot pamubay.

I feel stupid that the solution was so easy… I had headaches checking variables context and so on 🙂

---

<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:** [August 2, 2020, 1:16pm UTC](https://discourse.gohugo.io/t/page-resource-access-through-variable/27279/4 "2020-08-02T13:16:28Z")

</div>

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