What if you want one of the subkeys – how would you print the value of, say, author.current_mood in the template? What should we assign to $key in that case?
Right, but that only works if you know the name of the key in advance. If it’s in a variable, how do you use .Param? I’ll update the post so this is clearer.
@jxf I think @budpart answered you correctly. Just assign {{ $key := .Params.author.current_mood }}. Or are you asking how to range through all values?
Hmm, I think you may have misunderstood me: the variable in question is the author.current_mood part. In this example, you don’t know what key you’re looking up, and the key to look up is stored in that variable.
In other words, how can you find the appropriate value given only a single string?
Oh wow, this is really close, @digitalcraftsman! The sticking point is that $key could contain multiple levels to look up, as in my author.current_mood example, but index wants one argument for each level of nesting.
I think this would work if I split programmatically split $key up first into the individual segments, e.g. by splitting it along periods into a slice. Is there a way to “unpack” or “splat” slices and pass their individual members as arguments to another function? That would solve it.