I’m trying to create a list of pages in headless bundle, including images related to each page.
My directory structure looks like this:
- content
- english
- mybundle
- index.md
- first-mybundle.md
- second-mybundle.md
- first.jpg
- second.jpg
- mybundle
- english
first-featured.md
and second-mybundle.md
front matters look like this:
resources:
- name: image
src: first.jpg
resources:
- name: image
src: second.jpg
I’m creating the list in a partial template that looks like this:
{{ $headless := .Site.GetPage "/mybundle" }}
{{ $reusablePages := $headless.Resources.Match "*mybundle*" }}
<div class="highlights">
{{ range $reusablePages }}
<div class="highlight-box">
{{ printf "%#v" . }}
{{ with .Resources.GetMatch "image" }}
<img class="highlight-image" src="{{ .RelPermalink }}" srcset="{{ .RelPermalink }} 2x"
alt="{{.Title}}"
loading="lazy">
{{ end }}
<div class="highlight-description">
<h3>{{ .Title }}</h3>
<p>{{ .Content }}</p>
</div>
</div>
{{ end }}
</div>
The title and content prints just fine, but I’m not able to print the image - I’m missing something obvious. Can you help me, please?