HUGO

Iterate through nested front matter

I’m trying to use range to output a list of external links with their name and link.

I have set these as custom nested fields in the front matter, and hoped it would be the same as the {{ range .Site.Pages }} setup, but it doesn’t.

It just concatenates all the names as one single list item, and doesn’t use the hyperlinks at all.

Here is my front matter:

featured: 
  - fname:
    - "Forbes"
    - "The New York Times"
  - flink:
    - "https://www.forbes.com"
    - "https://www.newyorktimes.com"

And here is my layout:

	<ul>
		{{ range .Params.featured }}
		<li>
			<a href="{{.flink}}">{{.fname}}</a>
		</li>
		{{ end }}
	</ul>

What am I doing wrong?

Fixed it!

Changed my front matter format to:

featured: 
  - fname: Forbes
    flink: "https://www.forbes.com"
  - fname: "The New York Times"
    flink: "https://www.newyorktimes.com"

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