# How to sort yaml data by specific param

**URL:** https://discourse.gohugo.io/t/how-to-sort-yaml-data-by-specific-param/38976
**Category:** support
**Created:** [June 9, 2022, 6:32am UTC](https://discourse.gohugo.io/t/how-to-sort-yaml-data-by-specific-param/38976 "2022-06-09T06:32:24Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![zachy9](https://avatars.discourse-cdn.com/v4/letter/z/a8b319/32.png) [@zachy9](https://discourse.gohugo.io/u/zachy9)
#### Post date: [June 9, 2022, 6:32am UTC](https://discourse.gohugo.io/t/how-to-sort-yaml-data-by-specific-param/38976/1 "2022-06-09T06:32:25Z")

</div>

I’m ranging over a yaml file like this:

```
    {{ range (index .Site.Data .Params.gallery) }}
      {{ range . }}

```

Here’s a sample of some entries from the yaml:

```nohighlight
- src: "210723.mp3"
  title: "7/23/2021"
  date: 210723
- src: "210724.mp3"
  title: "7/24/2021"
  date: 210724
- src: "210727.mp3"
  title: "7/27/2021"
  date: 210727

```

I want to display the results in order using the “date” attribute since that will place them in the correct chronological order. At the moment it displays them alphabetically (i.e. 2/2022 comes before 7/2021)

---

<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: [June 9, 2022, 6:14pm UTC](https://discourse.gohugo.io/t/how-to-sort-yaml-data-by-specific-param/38976/2 "2022-06-09T18:14:05Z")

</div>

See [https://gohugo.io/functions/sort/#readout](https://gohugo.io/functions/sort/#readout). For example:

```auto
{{ range sort site.Data.foo "date" }}
  ...
{{ end }}

```

---

<div class="post-metadata">

### Author: ![zachy9](https://avatars.discourse-cdn.com/v4/letter/z/a8b319/32.png) [@zachy9](https://discourse.gohugo.io/u/zachy9)
#### Post date: [June 10, 2022, 1:14am UTC](https://discourse.gohugo.io/t/how-to-sort-yaml-data-by-specific-param/38976/3 "2022-06-10T01:14:20Z")

</div>

using that method to range on foo.yaml I get the following error:

```auto
<.Site.Data.foo>: foo is not a method but has arguments

```

---

<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: [June 10, 2022, 1:17am UTC](https://discourse.gohugo.io/t/how-to-sort-yaml-data-by-specific-param/38976/4 "2022-06-10T01:17:17Z")

</div>

Please post a link to the public repository for your project.

---

<div class="post-metadata">

### Author: ![zachy9](https://avatars.discourse-cdn.com/v4/letter/z/a8b319/32.png) [@zachy9](https://discourse.gohugo.io/u/zachy9)
#### Post date: [June 11, 2022, 3:32am UTC](https://discourse.gohugo.io/t/how-to-sort-yaml-data-by-specific-param/38976/5 "2022-06-11T03:32:25Z")

</div>

I don’t have one at the moment.

---

<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: [June 11, 2022, 4:43am UTC](https://discourse.gohugo.io/t/how-to-sort-yaml-data-by-specific-param/38976/6 "2022-06-11T04:43:08Z")

</div>

That is going to make troubleshooting somewhat difficult.
