Range inside a .GetByPrefix?


I’ve been toying with the new page bundle stuff for a few days and I have an idea in mind to create a gallery based on filename.

For now I use :

<div class="gallery">
{{ with .Resources.ByType "image" }}
{{ range . }}
{{ $scaled := .Resize "256x q80" }}
<div class="gallery-item">
<a href="{{ .RelPermalink }}">
<img class="thumbnail" src="{{ $scaled.Permalink }}">
{{ end }}
{{ end }}

But I want to be able to only range through images by prefix (gallery_) and only display those in the gallery.

For example an article folder in content would be like that :

  • MyArticleName
    • images
      • gallery_first.jpg
      • gallery_second.jpg
      • gallery_third.jpg
      • notingallery.jpg
    • index.md

Is that possible ?

You need to wait for the resolution of this Github issue. A fix will be released soon it should make your gallery easier to develop.

PS. Also read the release notes of Hugo 0.33

You might want to follow https://github.com/gohugoio/hugo/issues/4295#issuecomment-359038470

But in Hugo 0.33 the simplest is to just move all your gallery files into one single folder (gallery) and do something like:

{{ with .Resources.ByPrefix “gallery/” }}

1 Like

Thanks for your answers,

Will kindly wait for the bugfix point-release. :slight_smile:

For someone coming across this thread in future, note that .GetByPrefix has been deprecated and replaced with .GetMatch.

1 Like