Loop through a yaml dictionary in hugo

I am trying to write multiple descriptions in a post,

This is my frontmatter:

  subtitle: Sub1
  subdescription: Desc1 
  subtitle: Sub2
  subdescription: Desc2

and in my html:

{{ range .description }}

<h1>{{ .description.subtitle }}</h1>
<p>{{ .description.subdescription }}</p>


I tried that initially but I get a: can’t evaluate field categories in type interface {} error

So after some testing i found with this:

{{ range .my_description }}

<h1>{{ . }}</h1>


It writes out all of the data from the dictionary,
problem is is that, I cant seem to write out specific items for if i wanted to incase them in an html element,
this is what i tried : {{ .Params.my_description.subtitle }} ; {{ .subtitle }} but these didnt work.

additionally, i found that if i have two identical items in my dictionary, it wouldnt take the first pieces of data but would write out the last ones.

What am I missing here.

I found out that I had to use dashes in my dictionary like so:

     - subtitle:
     - subdescription

now i can get my data by simply going {{ .subtitle }}
and it even takes duplicates so i can add as many subtitles as i want

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.