I’ve been trying to figure out how to get partials to be imported dynamically based on array in my data yaml file. Partials themselves use data and I’m not able to get this working.
data/site.yaml file has content:
sections:
- banner
- carousel
- features
- cta
- infobox
partials with same names exist in partials/sections/ as:
partials/sections/banner.htm
partials/sections/carousel.html
etc...
In one of the layout files, I’m trying to iterate and import these partials.
{{ range .Site.Data.site.sections }}
{{ partial (printf "sections/%s.html" .) . }}
{{ end }}
But I come across error:
render: failed to render pages: render of “/home/user/Desktop/test.com/content/_index.md” failed: “/home/user/Desktop/test.com/themes/test/layouts/_default/home.html:4:5”: execute of template failed at <partial (printf “sections/%!s(MISSING).html” .) .>: error calling partial: “/home/user/Desktop/test.com/themes/test/layouts/partials/sections/banner.html:2:18”: execute of template failed at <.Site.Data.site.banner_title>: can’t evaluate field Site in type string
Any idea how I can do this properly?
Thanks