Is there a way to use .Resource.Match (or any other function) to target the images containing featured: true? I ultimately want to be able to range a map/list only containing images marked with featured: true.
Unfortunately, this does not work as expected. It seems that the params under resources in frontmatter is “unreachable”? Or maybe this looks for params added to the main part of the frontmatter, not under resources?
I have made a commit containing the relevant changes to the real code I’m working on, maybe it makes more sense looking at this than the mockup code I wrote in my first post?
Wow, it works, thank you! I think my mistake when trying a similar solution earlier was to use .Page.Resources.Match – which seems to only operate on the filename or name applied in frontmatter.
I’ll add some code giving context that might help others running into the same problem:
{{ $coverImages := where .Page.Resources "Params.cover" true }}
<div class="o-cover">
<div class="o-cover__container">
<ol class="o-cover__images">
{{ range $i, $e := $coverImages }}
{{ $n := add $i 0 }}
{{ $next := add $i 1 }}
{{ $prev := add $i -1 }}
{{ $total := len $coverImages }}
<li class="o-cover__images-item" id="image-{{ $n }}">
<img class="o-cover__images-item-img {{ with .Params.height }} -{{ . -}}{{ end -}}{{ with .Params.layout }} -{{ . -}}{{ end -}}" style="object-position:{{ .Params.position | default "center center" }}" src="{{ .RelPermalink }}" {{ with .Title }}alt="{{.}}" title="{{.}}"{{ end }}>
{{ with .Params.photographer }}
<div class="o-cover__images-item-credit"><p>Foto: {{ . }}</p></div>
{{ end }}
{{ if ne $prev -1 }}
<a class="o-cover__images-item-button o-cover__images-item-button-prev" href="#image-{{ $prev }}">prev</a>
{{ end }}
{{ if ne $next $total }}
<a class="o-cover__images-item-button o-cover__images-item-button-next" href="#image-{{ $next }}">next</svg></a>
{{ end }}
</li>
{{ end }}
</ol>
</div>
</div>