Hi everyone,
i’m new to Hugo and i’m testing it on a personal project i’m working on.
What i’d like to achieve is to use a shortcode to range through the results of my dataset in my page templates and i want it to be flexible by passing the name of the key value as argument so i can retrieve the data i need.
The problem i’m facing though is that the custom value is passed as string and throws me an error.
I’ve tried to use the slice and index functions for trying to map the collection the way i want but i can’t make this work.
Is it possible to do the thing i’m trying to achieve or should i hard code the range function in every page?
Thanks in advance to everyone who will take some time for helping me!
Some example code:
layouts/shordcodes/steps.html
{{$collection := .Site.Data.steps}}
{{$customKeyValue := .Get 0}} // Might be item-a or item-b according to the example
{{range $collection}}
{{range $customKeyValue}}
{{.title}}
{{.description}}
{{end}}
{{end}}
data/steps.json
{
"steps": {
"item-a":
[
{
"title":"step1",
"description": "Some text"
},
{
"title":"step2",
"description": "Some text"
},
],
"item-b": [
{
"title":"step 1",
"description": "Some text"
},
{
"title": "step 2",
"description": "Some text"
},
],
}
}