Retrieve image from headless bundle (easy one)

Possible to reuse a headless bundle image by naming it in a front matter variable and matching the name with .Resources.GetMatch? Seems like it ought to be. There is something wrong with my syntax here?

{{with .Params.featureImage}}
{{$match := . }}
{{with .Site.GetPage "section" "headless"}}
{{with .Resources.GetMatch $match }}
{{$featureImage = ( . ).Permalink }}

$featureImage is defined earlier in the partial. Params.featureImage is the name of the image in content/headless/, which is set headless = true

featureImage = "mountains.jpg"

$match is defined in the block. The error is

render of “section” failed: at <.Site.GetPage>: can’t evaluate field Site in type string

I always try $.Site.GetPage when I get these errors…

Thanks, it’s working. I thought it was a scoping issue.

It is. Default context for a partial is page, and within {{with .Params.featureImage}} the context is image. $ brings you back to the top level.


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.