Is it possible to target params from resources defined in frontmatter?

Lets say my _index.md frontmatter looks something like this and that this page/section has 10 additional images in its folder.

[…]
resources:
- src: some-file.jpg
  params:
    featured: true
    someotherparam: false

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.

{{ range where .Resources "Params.featured" true  }}
  ...
{{ end }}

Thanks @jmooring, for giving this a go.

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?

https://git.sr.ht/~rsolvang/hetlankheet-website/commit/8ee86bce9122b702b9f88335ad6ee564b40d0e33

When I clone your repository it shows the last commit was e8e154af on 17 Aug.

Where can I get an updated snapshot of your project?!

Disregard. Found params-debug branch.

1 Like

Actually, it does. You quoted the word true in the where clause.

Please see my initial response.

1 Like

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>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.