Hello,
I’m trying to iterate over the target
variable, to display the values in a partial template. The template only needs information from the given context.
Here is the simplified structure of my frontmatter :
title: "Title of the page"
formationSection:
- name: "Formation 1"
image: "/images/formation.png"
target:
title: "Who can participate"
items:
- "Developers"
- "Product Owners"
- "UX Designers"
- name: "Formation 2"
image: "/images/formation-2.png"
target:
title: "Who can participate"
items:
- "Developers"
I pass the corresponding context in my single.html
, like so :
<main class="sl-offer">
{{ with .Params.formationSection }}
{{- partial "formation-section.html" . -}}
{{ end }}
</main>
Then, in my formation-section.html
I’m able to display first level variables, like name
and image
:
<section class="formation">
<div class="tabs">
<ul class="tabs__selectors">
{{ range . }}
<li>
<button type="button">{{- .name -}}</button> <!-- prints correctly the name -->
</li>
{{ end }}
</ul>
<div class="tabs__content">
{{ range . }}
<div class="tab">
{{ .target.title }}
<ul>
{{ range .target.items }}
<li> {{ . }}</li>
{{ end }}
</ul>
</div>
{{ end }}
</div>
</div>
</section>
I’m then confronted to this error : <.target.title>: can't evaluate field title in type interface {}
, when I try to access the variables in the target
object
What would be the correct syntax ? I tried playing with the context but it didn’t change anything.
Thank you for your help