I’ve had some time to have a look at your repo.
In your content/_index.md
you have this:
components:
- article:
This seems incomplete?
If we take your code snippet line by line:
{{ range .Params.Components }}
This will iterate over your components in your frontmatter. components
is a list, so each iteration is one list item. In the first iteration the value of the dot inside this range is:
map[article:<nil>]
This dot is now what is being iterated over in the second range
. Looking at the first iteration of this range:
{{ range $component, $value := . }}
{{ $component }}: ( {{ $value }} )
{{ end }}
The results are:
article: ( )
Which reflects what is in your frontmatter, i.e., a key named "article"
and an empty value.
I don’t entirely understand what you are trying to actually do. Are you trying to pass the value of article
? If so, then you need to make sure you actually have a value to pass on.
I am assuming here that you want to be able to call a partial whose name you specify in the frontmatter. In this example, you want the "article"
partial. That inner range would then look like this:
{{ range $component, $value := . }}
{{ $component }}: ( {{ $value }} )
{{ partial (print "components/" $component) . }}
{{ end }}
Then you need to think about what you want to pass into your partial. Is it only the page context? Do you also want to pass the $value
along?
If you only want the page context, then as described a few posts up, you need to “save” the page context into a variable outside of the ranges:
{{ $page := . }}
{{ range .Params.components }}
{{ range $component, $value := . }}
{{ $partialname := (print "components/" $component) }}
{{ partial $partialname . }}
{{ end }}
{{ end }}
Then from your partial you can call {{ .Content }}
as per usual.
If you also want to pass $value
along, then you need to pass a dict:
{{ $partialname := (print "components/" $component) }}
{{ $args := dict "page" $page "foo" $value }}
{{ partial $partialname $args }}
Then from your partial, you call the page-related variables slightly differently:
{{ .page.Content }}
and you access your foo
:
{{ .foo }}
=> whatever $value
is