# Shortcode map variable

**URL:** <https://discourse.gohugo.io/t/shortcode-map-variable/48500>\
**Category:** tips & tricks\
**Tags:** shortcodes\
**Created:** [February 25, 2024, 8:36pm UTC](https://discourse.gohugo.io/t/shortcode-map-variable/48500 "2024-02-25T20:36:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![blong824](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/blong824/32/21435_2.png) [@blong824](https://discourse.gohugo.io/u/blong824)\
**Post date:** [February 25, 2024, 8:36pm UTC](https://discourse.gohugo.io/t/shortcode-map-variable/48500/1 "2024-02-25T20:36:36Z")

</div>

My question is basically the same as this [question](https://discourse.gohugo.io/t/shortcode-with-dynamic-data-variable/17751) 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

```auto
{{ $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.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [February 25, 2024, 8:47pm UTC](https://discourse.gohugo.io/t/shortcode-map-variable/48500/2 "2024-02-25T20:47:26Z")

</div>

Search the documentation for the index function.

---

<div class="post-metadata">

**Author:** ![blong824](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/blong824/32/21435_2.png) [@blong824](https://discourse.gohugo.io/u/blong824)\
**Post date:** [February 25, 2024, 8:58pm UTC](https://discourse.gohugo.io/t/shortcode-map-variable/48500/3 "2024-02-25T20:58:04Z")

</div>

Thank you so much!

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

market-data.html (shortcode)

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

```

Works as expected.

Here is the [link](https://gohugo.io/functions/collections/indexfunction/#example-load-data-from-a-path-based-on-front-matter-parameters) to the helpful docs.

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [February 27, 2024, 8:58pm UTC](https://discourse.gohugo.io/t/shortcode-map-variable/48500/4 "2024-02-27T20:58:15Z")

</div>

Closed on February 27, 2024, 8:58pm UTC

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