Go templates don't range on yaml in order!

Hi there,

I’m sharing this quick tip, as it bogged me for a moment today. When you use the range function in your Go templates over data files, the order of your data is preserved with JSON and TOML - but not with YAML.

Here’s the same data, first in TOML, and then in YAML, used to generate an online course page. You can see how the data gets messed up in the second case.

What if you still want to write YAML, as it’s convenient? You can use an online YAML to JSON converter, or use this Yaml-Json atom conversion package.

Happy Hugo-ing!

1 Like