How to best display all images from a folder

A few notes:

  • Your front matter param dataFile had an incorrect value. Change it from donut to XYZ
  • Your XYZ.yml listed images that did not exist in the branch bundle, so you would never get a match in your looping. So add one that does, e.g. 01.jpg
  • Since you’re using a branch bundle for your images, then the images must live in the same directory as the _index.md, so I moved them accordingly
  • To prevent the nil error, wrapped your image logic in a with
  • Instead of using the bundle image name as the image source, used the .Permalink
  • I left the debug lines in there so that you can see what is actually happening. Obviously remove them at some point
{{ with .Params.dataFile }}
<ul class="gallery">
  {{ $data := index $.Site.Data.shows . }}
  {{ $data }} <!-- debug -->
  {{ range $.Resources.ByType "image" }}
    {{ $bundleImg := . }}
    {{ $bundleImg.Name }} <!-- debug -->
    {{ range $data.media.images }}
      {{ . }} <!-- debug -->
      {{ if eq $bundleImg.Name .}}
        Equals {{ . }} <!-- debug -->
        <li><img src="{{ $bundleImg.Permalink }}" /></li>
      {{ end }}
    {{ end }}
  {{ end }}
</ul>
{{ end }}
2 Likes