Resources warning when upgrading to Hugo 0.34

When upgrading and running Hugo 0.34, I got the following warning:
Resources's GetByPrefix is deprecated and will be removed in a future release. We have added the more flexible Resources.GetMatch (find one) and Resources.Match (many) to replace the "prefix" methods.

Since I have several layouts using prefix ( for example such as {{ $cover := .Resources.GetByPrefix "cover" }} ) do I need to modify all my layouts to fit the new features with Resources.GetMatch ?

Yes.

Search/replace should be easy with tools like sed / perl / python /…

Thank you.
I am trying to get resources with pattern either “jpg” or/and “png”.
for the time being, my code is as follows:
{{ $cover := .Resources.GetMatch "cover.jpg" }} {{with $cover }} {{ $scaled := .Fill "550x350" }}

How can I get both *.jpg and *.png ?

This should work: .Resources.Match "cover.[jp][pn]g"… haven’t tried yet. You can find many examples here.

If you simply want to get a slice of all images, this would be better: .Resources.ByType "image".


  • .GetMatch returns only the first found match.
  • .Match returns a slice containing all the matches.
1 Like

It works fine !
Thanks

Awesome! Glad I could help.