# Get data by dynamic string

**URL:** <https://discourse.gohugo.io/t/get-data-by-dynamic-string/26425>\
**Category:** dev\
**Created:** [June 22, 2020, 12:14am UTC](https://discourse.gohugo.io/t/get-data-by-dynamic-string/26425 "2020-06-22T00:14:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mehmet\_kose](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mehmet_kose/32/11509_2.png) [@mehmet\_kose](https://discourse.gohugo.io/u/mehmet_kose)\
**Post date:** [June 22, 2020, 12:14am UTC](https://discourse.gohugo.io/t/get-data-by-dynamic-string/26425/1 "2020-06-22T00:14:39Z")

</div>

I have couple of data files and I list in duplicated layout files.

```
{{ with .Site.Data.money_transfer.DZ.sections }}
  <div >
    {{ range .items }}
      {{ partial "section.html" . }}
    {{ end }}
  </div>
{{ end }}

```

Can I call like this?

```
{{ with .Site.Data.money_transfer["DZ"].sections }}
...
{{ end }}

```

Because if I can, I can call dynamically with only one layout

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [June 22, 2020, 12:39am UTC](https://discourse.gohugo.io/t/get-data-by-dynamic-string/26425/2 "2020-06-22T00:39:01Z")

</div>

You may be looking for the [index](https://gohugo.io/functions/index-function/#readout) function. Here’s a sample:

```nohighlight
{{ $key := "DZ" }}
{{ with (index .Site.Data.money_transfer $key).sections }}

```

The `$key` can be any string, or read from a front matter param.

---

<div class="post-metadata">

**Author:** ![mehmet\_kose](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mehmet_kose/32/11509_2.png) [@mehmet\_kose](https://discourse.gohugo.io/u/mehmet_kose)\
**Post date:** [June 22, 2020, 10:01am UTC](https://discourse.gohugo.io/t/get-data-by-dynamic-string/26425/3 "2020-06-22T10:01:13Z")

</div>

that’s great! thank you for reply!

---

<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:** [June 24, 2020, 10:09am UTC](https://discourse.gohugo.io/t/get-data-by-dynamic-string/26425/4 "2020-06-24T10:09:14Z")

</div>

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