Hello there,
I am trying to process (resize, target webp and change quality) on a range of images.
Those images are stored in a page bundle. And listed in a frontmatter cascade.
Closest i have now with is this :
{{ with .Resources.ByType "image" }}
{{ range . }}
{{ $img := (.Resize "500x webp q75") }}
<img src="{{ $img.RelPermalink }}"/>
{{ end }}
{{ end }}
But this ↑ takes all the images in the “/images” folder of the bundle
I want to process and display only those under the gallery param in my front matter. Any idea how to solve this ?
Thanks a lot for reading me !
There are GetMatch/Match functions that matches the name
frontmatter of your resources. GetMatch gets the first one that matches, Match gets them all. Give them a name that starts with “gallery” and match on “gallery*”.
A related post:
Ooooh yes because the . is the range context. I totally missed that. I need to put in some time to learn Go properly.
For anyone who has a similar problem here’s my complete working solution:
{{ with .Site.GetPage "accreditations/index.md" }}
{{ $resources := .Resources }}
<div class="uk-section">
<h2>{{ .Title }}</h2>
{{ with .Content }}
<p class="summary">{{- . -}}</p>
{{ end }}
<ul class="uk-grid-small uk-child-width-expand@s uk-text-center" uk-grid>
{{ range .Params.accredit…
The documentation of GetMatch/Match:
Page resources -- images, other pages, documents, etc. -- have page-relative URLs and their own metadata.
Thanks I’ll look into it !
Ok I see, the resources.Match/GetMatch are pretty cool and pretty close do it, but it cannot work in my case.
This is because I have users that upload images from Netlify CMS, so I don’t have control over filenames. I’ll continue to look for something that can do it, in the meantime if anyone has an idea do not hesitate to chime in
Cheers.
Within a template (e.g., single.html)
{{ range .Params.gallery }}
{{ with $.Resources.GetMatch . }}
{{ with .Resize "500x webp q75" }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}
{{ end }}
Within a shortcode:
{{ range .Page.Params.gallery }}
{{ with $.Page.Resources.GetMatch . }}
{{ with .Resize "500x webp q75" }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}
{{ end }}
1 Like
Ooooooh yes that’s it ! Thanks a lot !
Completely overlooked that $ variable, I’ll look into it, seems important aha
1 Like
system
Closed
April 2, 2022, 7:21pm
7
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.