Accessing sub-object properties in data/file.json

We are developing a semi-complex site with hugo. So far we are loving it! GoHugo!

One thing I am not seeing any documentation or discussion about is accessing nested properties from a json file in the data directory.

It could be that I am doing something else wrong but I have a data folder in my theme with a global.json file which has a structure something like:

{ "head": { "foo": "blah" } }

And then in my template I am using $.Site.Data.global.head.foo to try and get the value “blah” but it is returning nothing. I see that you are adding the data to a map – is it possible to have nested maps?

Thanks!

Actually, scratch that. I can’t get any data to load at all…

Yes, that is the main point of the .Data structure. I would print out the global {{ printf .Data.global “%v” }} or something like that and see what it contains. My best guess is that you’ve got your JSON wrong.

There are some test cases for this:

The problem was that I wasn’t passing the current context to the partial. Thanks for the confirmation though.