Partials from md file with unique variables for each

So I found this thread:


It talks sort of about what I want to do but mine is a bit different.
I want to take a content file and build a template that has a variable number of partials and different color schemes that would be in .data.colors.black or .data.colors.blue etc

I want to create a TOML frontmatter that would look like (note the order would matter)

[[mpartial]]
path='path goes here'
color='black'
other='*'
[[mpartial]]
path='path goes here'
color='blue'
other='*'
other2='*'

Other variables would be things that would be sent to the partial to be used in only that specific partial file. Reason would be if I wanted to call the same partial again, I would want it to have different variables.

The partial would look something like

<table bgcolor={{ .backgroundcolor }}>
  <a>{{ .other }}<>
</table>

and finally the data file would look something like

backgroundcolor='#FFFFFF'
foregroundcolor='#000000'

or

backgroundcolor: #FFFFFF
foregroundcolor: #000000

if I did it in yaml (which is slightly easier but not a dealbreaker if I can’t use it)

How would I setup the layout file to do this? how would I range over the first partial, send it’s path to use the partial tell it to use the variables for the color file and also send in the other variables to be used by the partial? Is it possible?

Hopefully someone can help!

Thanks!

Edit: Fixed some things to clear it up.

So this was relatively simple to implement except for the color part, it seems that partials can’t see the color data file and I don’t know how to send it down. One thing to note is that not all colors will be used in every template. Just if that matters. Anyway here’s the code I used to send my content file above to create a partial.

{{range .Params.mpartial}}

{{ partial .path . }}

{{end}}

using this as my content file

[[mpartial]]
path='path goes here'
color='black'
other='*'
[[mpartial]]
path='path goes here'
color='blue'
other='*'
other2='*'

really simple actually, I range through a mpartial array of maps. For each map, I send the path variable and the rest of the context to a partial.

Works really well except that I can’t easily send my color map from my data file. If anyone has any insight into pulling the color data map into each partial depending on color set in the mpartial that would be awesome as it would allow me to migrate my current project over to Hugo.

Cheers!