Get yaml dictionary data in hugo


I am trying to create a sort of sub- Title and Description list in hugo.
So you would feed it a yaml Dictionary basically and it will write them all out on the page.

right now I’ve tried creating the yaml scaffolding like this:

 subtitle: SubTitle
 subdescription: SubDesc

I tried testing this, by referencing them in the html like this:

{{ .description.subtitle }}
{{ .description.subdescription }}

My logic didnt workout, if i just use this scaffolding:

description: Some random data
{{ .description }}

The description seems to come through well,
what is the issue?
Also are you able to loop through the dictionary in hugo aswell?

Hi there.
You have multiple issues:

  • YAML is indentation-sensitive, so your dict keys need 2 spaces
  • The front matter description is a reserved word in Hugo, so try something else, like my_ description
  • To access custom front matter params, you need to use .Params


Given this front matter

title: My Page
  subtitle: SubTitle
  subdescription: SubDesc

And this template logic

{{ .Params.my_description.subtitle }}
{{ .Params.my_description.subdescription }}

You get this output

1 Like

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