Shortcode map variable

My question is basically the same as this question from 2019.

I want to pass a file name into a shortcode like this

{{< market-data src="file_022524.json" >}}

This file is saved under the data/subData/ folder.

{{ range .Site.Data.subData.file_022524 }}
works fine but I would like this to be dynamic.

I’ve tried

{{ $source := .Get "src"}}
{{ $data := print ".Site.Data.subData." $source }}

{{ range $data }}
throws an error. I am guessing because it is a string and it is expecting a map.

New to Hugo and any help would be much appreciated.

Search the documentation for the index function.

Thank you so much!

market-data.md
{{< market-data src="file_022524.json" >}}

market-data.html (shortcode)

{{ $source := .Get "src"}}
{{ range index .Site.Data.markets $source }}

Works as expected.

Here is the link to the helpful docs.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.