Can't evaluate field GetByPrefix in type resource.Resources

Really having a hard time wrapping my head around GetByPrefix function.

{{ with .Site.GetPage "section" "images" }}
  <h2>From {{ .Title }} (images)</h2>
  {{ $resources := .Resources.GetByPrefix "logo"}}
  {{ range $resources }}
    {{ with . }}
      {{ $image200x := (.Resize "200x") }}
      {{ $image400x := (.Resize "400x") }}
      <img src="{{ $image200x.RelPermalink }}">
      <img src="{{ $image400x.RelPermalink }}">
      <br />
    {{ end }}
  {{ end }}
{{ end }}

The code is returning the following error: can't evaluate field GetByPrefix in type resource.Resources

Running Hugo v0.49

GetByPrefix was added, quickly replaced with GetMatch, and then removed.

Looking at your code, what you want is something ala {{ $resources := .Resources.Match "logo*"}}

Or use .GetMatch if you only want 1.

1 Like

Thanks Bep, all is working now.

Would it be possible to improve the error messages? For example in this case it would be nice if Hugo tells you that the function is deprecated and you should use .Match function.

1 Like

We do that. When we deprecate we give a detailed WARNING. After some Hugo versions, that WARNING becomes an ERROR … But when we finally remove the method, it is no longer deprecated, and any error goes away.