To show some content previews in another part of my site, I’d like to loop over all items from one section and access the front matter of each page. So far I’ve settled on this:
{{ range ($.Site.GetPage "example_section").Data }}
{{ partial "debugprint" . }}
{{ end }}
This lets me iterate over a list of Page
objects. The only thing I can’t seem to figure out now - even with the excellent debugprint helper I found online - is where I can access the front matter of each page. How do I get this info?
Hi,
User-defined front matter variables are accessible under .Params
: https://gohugo.io/content-management/front-matter/#user-defined
That was the first thing I tried before coming here, but I get this error when I try that:
execute of template failed: template: index.html:10:48: executing “main” at <.Params>: can’t evaluate field Params in type interface {}
Hi,
So I re-read your original question. I would suggest you use this snippet instead for looping over your pages. .Params
should be accessible then:
{{ range where $.Site.RegularPages "Section" "example_section" }}
{{.Params}}
{{ end }}
Yes, that’s exactly what I’m going for! Thanks pointyfar!