Order structures in data folder

Hi all,

I’m trying to display some content that I’ve got in a TOML file inside my data folder in a specific order. I’m following the basic example here.

My issues.toml file looks like this:

title = "The Start Issue"
published = "1979-05-27"

title = "The Imperfection Issue"
published = "1982-05-27"

title = "The Friendship Issue"
published = "1980-05-27"

And then I’m displaying them in a layout file with

  {{ range $.Site.Data.issues }}
     <li>{{ .title }}</li>
  {{ end }}

It shows up just fine, but I really want to order my data by published date. Is this possible with an extra argument to the range function? Currently, I can’t quite figure how the data is ordered by default.

Thanks so much,

See https://gohugo.io/templates/functions#sort

1 Like

But note that for the date sorting to be something other than string sorting, you should consider making your dates into “proper dates”.

As an example, this weird construction from the Hugo docs would not work with strings:

Another “also”: The data structure you got in the above, I think, will become a Go map, which is not ordered. (or: the order is undefined).

Look at

Thanks, Bep! Working like a charm :slightly_smiling: