Ordering site params by source order

I just switch my conifg file from .yaml to .toml. Within the config I have a site-wide staff parameter. Before, as a yaml file, the output was sorted by source oder. After I switched to toml the order appears to default to alphabetical. How can i order by source again?

config.yaml

params:
  staff:
    -
      name: "Alex Doe"
      title: "CEO"
    -
      name: "Colin Doe"
      title: "Operations"
    -
      name: "Bart Doe"
      title: "VP"

Outputs: > Alex, Colin, Bart

config.toml

[params]
  [params.staff]
    [params.staff."Alex Doe"]
      name = "Alex Doe"
      title = "CEO"
    [params.staff."Colin Doe"]
      name = "Colin Doe"
      title = "Operations"
    [params.staff."Bart Doe"]
      name = "Bart Doe"
      title = "VP"

Outputs: > Alex, Bart, Colin

file

<ul>
  {{ range .Site.Params.staff }}
    <li>{{ .name }: {{ .title }}</li>
  {{ end }}
</ul>

Your conversion was not only from YAML to TOML, but in the process you also converted an array into a map.

Arrays are order guaranteed where maps are not. There is no such concept as “source order” with maps because there is no order at all.

If you want to retain the order in the source you could either create an array in TOML or add an order field to the map and order by it within your template.

Yeah that makes sense. I’m assuming something like this should work? Currently I’m getting no output:

[params]
  foo = ["bar", "biz", "baz"]

<pre>{{ .Site.Params.foo }}</pre>

{{ range .Site.Params.foo }}
  {{ . }}<br>
{{ end }}

@spf13 I didn’t realize this until I just looked at the template documentation, but maps in templates operate differently than in standard Go code. As long as the keys are naturally comparable, it always outputs it alphabetically. (from the docs)

{{range pipeline}} T1 {{end}}
	The value of the pipeline must be an array, slice, map, or channel.
	If the value of the pipeline has length zero, nothing is output;
	otherwise, dot is set to the successive elements of the array,
	slice, or map and T1 is executed. If the value is a map and the
	keys are of basic type with a defined order ("comparable"), the
	elements will be visited in sorted key order.

I don’t see anywhere in the documentation that allows you to order the results, except for .ByCount in taxonomies. Is that something that anyone can use by concatenating By and a field name e.g. ByFoo, '.ByOrder`, etc.?

http://gohugo.io/taxonomies/ordering/

I saw that, but it looks like it only applies to Taxonomies. If I’m not mistaken, @brad is looking for a way to order just a standard map inside of .Site.Params.

Oh, missed that. There isn’t a predefined way.

@brad That being said, your best bet is to not use the actual name as the map key, but keys that are pre-ordered. It’s not the most elegant solution, but it’ll work.

Thanks. I think I’m just going to go back to a yaml array (couldn’t get a toml array working) for now, and come back to refine this later.