Looking into Hugo to develop a static, and with little coding knowledge/expertise. Kinda learning as I go along… I apologize in advance if it is a trivial question or worse namely not knowing at all where it is all about.
I have a index.html, with around 7 html sections. Each section has a title, a description and an image which are defined in the config.toml as so:
[params]
This is Section1
[params.section1] enable = true title = "Section 1" description = "Some text about section 1" img = "section1.jpg"
This is Section2
[params.section2] enable = true title = "Section 2" description = "Some text about section 2" img = "section2.jpg"
From there the index is calling the sections
{{ if .Site.Params.section1.enable }}
{{ partial “section1.html” .}}
{{ end }}
{{ if .Site.Params.section2.enable }}
{{ partial “section2.html” .}}
{{ end }}
Finally, the partial currently looks like so:
{{ with .Site.Params.section1.title }}{{ . | markdownify }}{{ end }}
I want to clean that up and create a single ‘section.html’ (instead of 7 sections with quasi identical code) using the variables I define in the config.toml. I would prefer to keep the index calling based on the
{{ if .Site.Params.section1.enable }}
So I would like to pass a variable within the index.html to the partial ‘section.html’ so that I can call the variables of the toml from that specific section. In other words:
{{ if .Site.Params.section1.enable }} {{ partial "section.html" .(dict "context" . "section" "Site.Params.section1") }} {{ end }}
This way, correct me if I’m wrong, I could write in the partial something like
{{ with .context.section.title }}{{ . | markdownify }}{{ end }}{{ with .context.section.img }}{{ . | markdownify }}{{ end }}
And would only need 1 section to create 7 if enabled in the toml.
Would this make sense, and if so, how would I go about it?