Hi Everyone,
I’ve been working on my first Go and Hugo project recently and am really enjoying it. Thank you to all of those who have clearly put in a great deal of work.
I’m trying to get to grips with templating in Hugo and with data manipulation whether simply from files in the data directory of with getJSON.
I would be really grateful if anyone is able to give some tips/tricks and examples of how best to get at and use data at the various different levels of a json (or equivalent) structure. I’m managing to get at certain elements but clearly need to build my knowledge and understanding further!
For example, here is a data file I’m working with called robots.json
[
{
"robot_type" : "one",
"models" : [
{
"id": 175676783,
"Name": "Triton",
"ALink": "https://bbc.co.uk/news"
},
{
"id": 27635689,
"Name": "Mars",
"ALink": "https://bbc.co.uk/sport",
"otherNames" : ["red rover", "planetary explorer", "red duster"]
},
{
"id": 334756,
"Name": "Active 2i",
"ALink": "https://bbc.co.uk/weather"
},
{
"id": 4895709,
"Name": "europa",
"ALink": "https://bbc.co.uk/"
}
]
},
{
"robot_type" : "two",
"models" : [
{
"id": 124778,
"Name": "Mars",
"ALink": "https://bbc.co.uk/contact"
},
{
"id": 876523,
"Name": "Active 2i",
"ALink": "https://bbc.co.uk/terms"
}
]
}
]
What I want to be able to do is to loop through the various models and extract any and all data either using a loop or separately getting a specific pice of information for a particular robot.
I’m making use of range currently but have struggles to access beyond the first layer. I’m very new to Hugo and go and would be able to do this in js so I’m sure I’ll get there but any help along the way would be great!
If I can help to explain what I’m trying to do further, do just let me know.
Thanks again!