Retrieving page resources in html page layout

Hi, I’m having issues here.
My homepage is mostly layout and front matter.

Folder looks like this:

content/
└── home
       └── index.md
       └── test.jpg

I went on to add this code to home.html (layout):

{{ with .Resources.Match "test.jpg" }}
   <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">
{{end}}

The error I’m getting is this:

ERROR 2020/08/26 21:50:18 Failed to render pages: render of "page" failed: "C:\Users\renau\OneDrive\Documents\Websites\Framework\layouts\_default\home.html:27:17": execute of template failed: template: _default/home.html:27:17: executing "main" at <.RelPermalink>: can't evaluate field RelPermalink in type resource.Resources

.Resources.Match will return an array: https://gohugo.io/content-management/page-resources/#methods

You have to range over the result beforeaccessing the .RelPermalink.

{{ with .Resources.Match "test.jpg" }}
  {{ range . }}
    {{ .RelPermalink }}
...
2 Likes

Thanks, now I don’t have an error but still nothing shows up. Why would that be?

I don’t know. Is it actually finding a match? It would be easier to help you if you had your code somewhere we can have a look at.