I’m trying to use a front-matter param to define the path to an image that I want to resize. I can get it to work when I hard code in the file path, but when I try to define the file path with a variable, it gives me a nil pointer error when it tries to resize, so it seems like .GetMatch isn’t working like I expect.
This code works perfectly for me:
{{ $photo := (.Site.GetPage "/images").Resources.GetMatch "file/path.jpg" }}
{{ $resizedPhoto := ($photo.Resize "100x").Permalink }}
<img src="{{ $resizedPhoto }}"</img>
But this code doesn’t:
{{ $photoURL := "file/path.jpg" }}
{{ $photo := (.Site.GetPage "/images").Resources.GetMatch $photoURL }}
{{ $resizedPhoto := ($photo.Resize "100x").Permalink }}
<img src="{{ $resizedPhoto }}"</img>
nor does this:
{{ $photoURL := "file/path.jpg" }}
{{ $photo := (.Site.GetPage "/images").Resources.GetMatch (printf "%q" $photoURL }}
{{ $resizedPhoto := ($photo.Resize "100x").Permalink }}
<img src="{{ $resizedPhoto }}"</img>
Here’s the relevant error:
at <$photo.Resize>: nil pointer evaluating resource.Resource.Resize
In practice $photoURL would be defined by a param, but this illustrates my problem. All of the code examples are being run in the exact same spot, trying to eliminate context as the source of the promble. Any ideas?