PROBLEM: .GetMatch "header" failure


I’ve fallen at the first hurdle, and would be grateful for some help.

My header is:

title: "My First Post"
description: "The description of the post"
date: 2020-02-05T11:09:31Z
    - name: header
      src: images/sunset.jpg

My code is:

<div class="medium-5 cell">
  {{ $image := .Resources.GetMatch "header" }} 
  {{ if $image }} 
  {{ else }} 
  {{ end }}

My output is:

<div class="medium-5 cell">
[NO IMAGE]       

I’m clearly fundamentally misunderstanding the (limited) examples in the documentation. May I ask someone to explain why this is failing, and how I correct it?

Thank you

Does this image exist?

It does. I’ve also tried

- name: header
  src: sunset.jpg

and placing sunset.jpg in the same directory as the entry.

What do you get with

Context: {{.}}
Resources: {{.Resources}}

If you have your code somewhere we can have a look at, it may be easier to help troubleshoot.

Also: what hugo version

Update: I followed this tutorial, constructed a folder, renamed the entry as and placed it in the folder, constructed a subfolder images and placed the image in that, and it worked.

I image this is obvious once the entire documentation base is committed to memory - I apologise for the trivial question :slight_smile:

I appreciate you spending some time on this - it looks like I haven’t understood the folder structure properly and may have wasted your time, for which I apologise.

Good to hear you’ve figured it out. No need to apologise, we were all beginners once. This might also help future new users who might encounter this.

Contributions to improve the docs are always welcome. :slight_smile:

1 Like