Can a variable be used as part of a path with the GetMatch method?

Hello guys,

I’m slowly learning hugo but sometimes i get stuck trying to do something, so your help is gold for me.

The question i have is:

Can a variable be used as part of a path with the GetMatch method?

something like this:

{{ .Resources.GetMatch “**/$variable.jpg” }}

or this

{{ .Resources.GetMatch “**/{{ $variable }}.jpg” }}

where $variable in my case is a custom front matter {{ $variable := .Params.myfrontmattervariable }}

I need the “**/” becaouse the resource im trying to find is in a subfolder inside a headless page bundle, and i can’t put it in the root.

Thank you.

Without testing:

{{ .Resources.GetMatch (printf "**/%s.jpg" $variable) }}

See here:

{{ $original := .Page.Resources.GetMatch (printf "%s*" (.Get 0)) }}
2 Likes

I was playing with printf but couldn’t find the solution.

Your code works like a charm! Thank you very much