YAML front matter parameters random order

I’m posting this here because I’ve encountered a bizarre issue with front matter parameters being rendered in a random order and not as I typed them.

It took a while before I discovered that non-latin line breaks (in this case greek) were causing this weirdness.

So if you ever encounter this behavior just eliminate the non-latin line break and type it again in english (or another language that uses the latin alphabet).

And just for reference’s sake my nested YAML parameters look like this:

---
color:
  grey: γκρι
  ecru: εκρού
  saumon: σομόν
  gold: χρυσό
---

And I am rendering them with the following function.

{{- range $key, $value := $.Params.color -}}...{- end -}}

I don’t think this is a Hugo bug. It looks more like a YAML bug.

Oh and TOML doesn’t even support this kind of syntax -at least as far as I can tell-.

EDIT
As pointed out this is a Go feature and the above was a temporary fix. Everything is random again. Lucky me.

Oh and TOML doesn’t even support this kind of syntax -at least as far as I can tell-.

For TOML, I think you want the following:

+++
[color]
  grey = "γκρι"
  ecru = "εκρού"
  saumon = "σομόν"
  gold = "χρυσό"
+++
1 Like

It is a Go feature.

You are correct. Rebuilt the site and now the keys are random again.

I ended up calling these parameters by name. Not ideal but it works and I’ll live with it.

I was unable to make the sort function work with nested front matter parameters as it needs them to be in a sequence. collections.Sort | Hugo

Also the following threw a too many declarations in command error.

{{ $key, $value := $.Params.color }}
{{ with $key }}<input type="radio" id="{{ $key }}" name="$value" />{{ end }}

There is an open issue on Github that seems to be related: Need a way to keep hash keys while sorting · Issue #3763 · gohugoio/hugo · GitHub