[SOLVED] Access front matter params in taxonomies loop

How do I access a front matter param in a .Site.Taxonomies loop.

Ex: My post front matter looks like this:

---
title: post title
categories: ["reviews"]
author: "author name"
score: 4
---

I can access title with .Page.Title, but how do I access author and score in the loop below:

{{ range first 5 .Site.Taxonomies.categories.reviewsl }}
  {{ .Page.Title }}
  {{ .Params.author }} // doesn't work
  {{ .Params.score }}  // doesn't work
{{ end }}

Are you getting an error or just a blank page? If the former, my first guess is that you might have front matter where author and score is not present. Have you tried checking for the presence of the aforementioned front matter first?

{{with .Params.author}}{{.}}{{end}}
{{with .Params.score}}{{.}}{{end}}

[EDIT]: Actually, maybe it’s that you need to set a couple variables (variadic). Can you point me to a repo for a little more context?

Unfortunately, I haven’t pushed by my changes to a repo yet because my code contains some API secret keys. I tried your code above and got the same error (line 14, col 47)
ERROR: 2017/02/22 14:33:03 general.go:236: Error while rendering page : template: theme/index.html:14:47: executing "theme/index.htm

Line 14:

  • {{ .Page.Title }} // {{with .Params.author}}{{.}}{{end}}

  • Column 47 starts with .author

    Try it.

    {{ range .Site.Taxonomies.categories.reviewsl.Pages }}
      {{ .Title }}
      {{ .Params.author }} // doesn't work
      {{ .Params.score }}  // doesn't work
    {{ end }}
    
    3 Likes

    This worked! Thanks

    3 Likes