Get first image in a bundle

This should be easy but I can’t get it to work: For use in a summary template as thumbnail/featured image, how do I just get the first image in the bundle if no featured image is specified in the front-matter?

Untested but you should try:

{{ range first 1 (.Resources.ByType "image") }} 
 <img src="{{ .Permalink }}" />
{{ end }}


{{ with (index (.Resources.ByType "image) 0) }}
 <img src="{{ .Permalink }}" />
{{ end }}
1 Like

Thank you! That works.

I wonder if I’ll ever get my head round Go syntax … :thinking:

I wrote this modest piece a while back, maybe it can help you:


Thanks, that’s very helpful. Although to be honest other languages don’t make much sense either! And I can’t say I’ve even heard of those ‘well known templating languages’ Twig, Blade or Liquid … :wink:

I’m fine with HTML and CSS but anything with functions and loops and variables seems to just give me a headache …

You’re blog certainly helps perpetual newbies like me grok some of this stuff. Keep it up!