Hello!
I’m trying to compose a range statement with a variable in it to be “dynamic” if the source JSON it has its information from gets updated.
The JSON files are named like this “firstlastname.json” and I have no trouble accessing / working with them from {{ range $.Site.Data.players.firstlastname.information }}
But as I said, it works fine if I manually enter the filename in the range (range $.Site.Data.players.firstlastname.information), so I THINK this might not be the problem, but I put the range with variable together wrongly.
Interestingly I have no error while implementing the range (index $.Site.Data.players $myjsonfile).information, but nothing in between the range and the end is actually loaded on the page, even if its plain text.
{{ $myjsonfile := "firstlastname" }}
{{ range (index $.Site.Data.players $myjsonfile).information }}
{{ .fullname }}
{{ end }}
Try it:
git clone --single-branch -b hugo-forum-topic-40374 https://github.com/jmooring/hugo-testing hugo-forum-topic-40374
cd hugo-forum-topic-40374
hugo server
Thanks, that was it! Since the other topic also had the example for declaring the variable starting with a dot and it matched the general construction of the range, I was convinced I also had to declare it like that. Removed the dot and it worked as expected. Many thanks for your time!