Hello. How can I get data in a range?
{{ range $k, $v := .Scratch.Get "data" }}
{{ $data := .Site.Data.modules.my_module.line_{$v} }}
{{ end }}
I tried that
{{ $test:= delimit (slice ".Site.Data.modules.my_module.line_" .item_id) "" }}
{{ $data := $test }}
{{ $data }}
You can try to use something like (not tested)
(printf ".Site.Data.modules.my_module.line_%s" $v)
See https://gohugo.io/functions/index-function/
data/modules/my_module.json
{
"line_1": {
"name": "Tom",
"age": 26
},
"line_2": {
"name": "Marie",
"age": 31
}
}
template
{{ .Scratch.Set "data" (slice 1 2) }}
{{ range .Scratch.Get "data" }}
{{ index site.Data.modules.my_module (print "line_" .) }}
{{ end }}