In the following code, I am failing to come up with the right syntax to access some page/site frontmatter with variables correctly.
I know I can say “give me .Params.author” but I’d like to say “$key := “author”, give me .Params.$key” in go/Hugo. Can anyone help with a generalized solution to this kind of lookup? Ideally it shouldn’t be .Params specific because I also need to use it with .Site.Params and just want to know in general how this should be done. I didn’t recognize any obvious accessor functions in the docs and I know this is blindly stupid… sorry.
[In this full snippet, I’m trying to output some json for structured data and don’t want to type the exact same code for author, creator, and accountablePersons.]
{{- range $pubfield := (slice "author" "creator" "accountablePersons") }}
{{- $credit := index .Site.Data.authors (or (.Params.$pubfield) (lower .Site.Params.$pubfield)) }}
{{- if $credit }}
"{{ $pubfield }}": {
{{- range $key, $val := $credit }}
{{ $key}} : {{ $val }}
{{- end }}
},
{{- end }}
{{- end }}