Hi all!
Since yesterday, I have been trying to insert a partial via a range loop and have not been able to find a solution online. The partial to be inserted is a variable from a data file.
{{ range .Site.Data.home_sections }}
{{ partial .file . }}
{{ end }}
When I add <p> tag for debugging purposes, the correct filename is output inside of the <p> tag. However, I don’t know in what form I need to pass this to the partial function, so it will be inserted.
{{ range .Site.Data.home_sections }}
<p>{{ .file }}</p>
{{ partial .file . }}
{{ end }}
I tried the following variants, but none of them did work:
{{ range .Site.Data.home_sections }}
{{ partial .file . }}
{{ end }}
{{ range .Site.Data.home_sections }}
{{ partial ".file" . }}
{{ end }}
{{ range .Site.Data.home_sections }}
{{ partial {{ .file }} . }}
{{ end }}
{{ range .Site.Data.home_sections }}
{{ partial "{{ .file }}" . }}
{{ end }}
This is the `home_sections.yml` File i use for definition of the sections:
- file: about.html
- file: projects.html
- file: about.html
- file: about.html
And this would be the manual way, I try to replace with a range. When doing like so, it works, but this isn’t the goal:
{{ partial "about.html" . }}
{{ partial "projects.html" . }}
{{ partial "about.html" . }}
{{ partial "about.html" . }}
The goal is to don’t hard code the order of the sections, so the user can change the order of the section in one place via yml (in the end via a headless cms).
Does anyone know why this is and whether it is even possible? Or is there even a better solution?
Thanks in advance and have a great day!
