and fetch the value of this nested parameter. Here is a reference implementation illustrating the general idea. If this is agreeable with the Hugo folks I’d be happy to work on this and submit a PR.
One thing I foresee as being a big sticking point for success here is that sometimes Hugo uses map[string]interface{} and sometimes it uses map[interface{}]interface{},
as shown here. That means that it’ll be a little harder to write a consistent definition of how things should work.
After some discussion with other folks, I have submitted a PR that I think addresses this problem:
I thought the difference in interface types would be an issue in writing this, but fortunately @spf13 has cast.ToStringMap, which is literally the exact function I needed and didn’t want to have to write since it’s not really in-scope for Hugo.
Should also be fine, but is less flexible. The .Param method (if called on Page) looks first in page params, then in site param, and you don’t have to worry about nil pointers that much.
I am not familiar with the .Map key what’s that about and how can I use it in my example? A key I can create that can map to deeper keys? Is this documented?
in my toml
[params.youtube]
# maxwidth = "800" default maximum width for all youtubes default is 450
# wpad = "50" # padding on both left and right when view width is < maxwidth default is 5
in the post above where I said that’s what I wanted. That’s why I used the alternative
and the alternative you just suggested is no better with similar error
{{ with $.Params "youtube.disable_thumbs" }} nothumb="yes" {{ end }}
ERROR 2017/04/11 19:16:44 error processing shortcode theme/shortcodes/youtube.html
ERR: template: theme/shortcodes/youtube.html:32:16: executing "theme/shortcodes/youtube.html" at <$.Params>: Params has arguments but cannot b
e invoked as function
just confirming that this worked! No more Hugo errors
{{ with $.Page.Site.Params.youtube.disable_thumb }} nothumb=“yes” {{ end }}
It never occured to me prefacing with .Page would get the reference correct. I always just assumed (logically?) that $.Site was always accessible everywhere (globally), shortcodes or partials or pages. It seems it is but only via the page being rendered.
maybe the points of this thread should be in the support or tips and tricks section? I can do that. In the docs?
but…'ll make a post since .2 just came out and it will be awhile. What’s a good post title for this issue that will bring the right search terms to it? “Accessing deeply nested site config parameters” ??
@dkebler I figured I would attempt to leverage your use case (and the feedback @bep gave us on this thread) to make the docs around shortcode templating a bit more comprehensive in the new docs site. I’d love some feedback if you have a moment