Looking for image in a bundle folder

I want to go through images in a bundled page and add them to the markup. The problem is, that fileExists looks from the webroot. I looked into .File.Dir and other file variables, but using them leads to errors in my partials:

{{ with .Params.images }}{{ range first 6 . }}
	<meta property="og:image" content="/{{ .File.Dir }}/{{ . }}" />
{{ end }}{{ end }}

error:

ERROR 2019/07/03 13:57:32 Rebuild failed:

ERROR 2019/07/03 13:57:32 Failed to render pages: render of "page" failed: execute of template failed: template: post/single.html:9:7: executing "post/single.html" at <partial "head" .>: error calling partial: execute of template failed: template: partials/head.html:3:3: executing "partials/head.html" at <partial "head/open_graph.html" .>: error calling partial: "/home/patrick/Projects/Me/samui-samui.de/layouts/partials/head/open_graph.html:12:45": execute of template failed: template: partials/head/open_graph.html:12:45: executing "partials/head/open_graph.html" at <.File.Dir>: can't evaluate field File in type string

I assumed .File to be related to the .md-file that is currently parsed, but that does not seem to be the case?

This one solved itself by debugging the page variables. It turns out that the Pageressources are filled automatically with info about all images in the folder. I thought they would have to be defined by frontmatter explicitly. Impressive.

{{ with .Resources.ByType "image" }}{{ range first 6 . }}
	<meta property="og:image" content="{{ .Permalink }}" />
{{ end }}{{ end }}
1 Like