+++
[params]
images = ['images/post-7/cover.jpg']
+++
I am not getting any image with this code
{{ with .Params.images }}
{{ with index . 0 }}
{{ with resources.Get . }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ else }}
{{ errorf "Unable to find image %s" . }}
{{ end }}
{{ end }}
{{ end }}
I need it as a fallback for an image variable I have.
irkode
October 15, 2025, 10:10pm
2
which with does not deliver a result? add some errorf statements in an else to see
if your error is printed - where is your image located assets/images...? if i’s in the page bundle try $.Resources.Get
what’s the sourrounding code? sure to have the right context?
lot of guesses with just that snippets…
for completeness: capitalization on *nix based systems.
tifenak
October 15, 2025, 10:43pm
3
I tested on a blank hugo site hugo new theme quicksite --themesDir .
irkode
October 16, 2025, 6:00am
4
quite brief answer for the possible causes listed above. another point added to the ones above: maybe a corrupt image
i plugged in your code in a “blank hugo site” (150.0) and it works - as expected.
Trying to replicate yours to get it fail like it fails for you without knowing anything about the place where it fails, what you have and any messages/debug … is waste of time
what about sharing that complete small repo?
1 Like
tifenak
October 16, 2025, 10:01am
5
You are correct that it works when calling the image directly. I suspect I have a context issue. Here’s the repo GitHub - tikenak-20/quicktest: Hugo quick test site
Files of interest.
home.html
partials/thumbnails.html and partials/featured-image.html
assets/images/post-1/cover.jpg
content/posts/post-1.md
The image does show up in other list pages, except the homepage.
Edit: And the was issue contextual (the dot.) I had to pass the page context to the home image partial as a dictionary.
in featured image partial {{- $images := partial "thumbnails.html" .Page }}
in home.html {{- partial "list/featured-image.html" (dict "Page" . "Resources" .Resources "LazyLoading" $lazyload ) }}
irkode
October 16, 2025, 10:42am
6
yepp. whatever you tried with passing .Resources wont work. just pass the page
if i were you I would use a page resource for that instead of a global resource - your image seems to be page dependent
1 Like
tifenak
October 16, 2025, 10:44am
7
I made an edit to previous comment.
I am actually recreating my theme for multi-use purposes and capturing all possible scenarios where images may exist. Hence why I am doing the test proofing.
irkode
October 16, 2025, 11:24am
8
glad it works now. so pointing to context wasn’t that bad. we all have been there
tifenak
October 16, 2025, 11:29am
9
It was the most frustrating thing for me when I first used Hugo.
system
Closed
October 18, 2025, 11:29am
10
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.