Evaluate a string

config.toml

[params]
    [params.fruits]
        title = ["Fruits"]

#1

{{ $.Site.Params.fruits.title }}

#2

{{ $myTitle := printf "$.Site.Params.%s.title" "fruits" }}
{{ $myTitle }}

#1 evaulates to Fruits but #2 does not. Why is that?

printf outputs a string. So,

{{ $.Site.Params.fruits.title }} vs {{ "$.Site.Params.fruits.title" }}

You probably want to use index instead: https://gohugo.io/functions/index-function/

2 Likes