[support or feature] ordering range .Site.Data contents

Hi everyone,

I tried to search for it and I tried the order solution and the sort solutions but I cannot get it to work.

in the data folder I have an erp_leaft.toml with this data:

[branche]
  name = "Lösungen nach Branche"
  short_name = "nach Branche"

  [branche.malerundgipser]
    weight = 0
    name = "Maler und Gipser"
    description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iste deserunt, ducimus..."
    internal_link = "produkte/enterprise/maler-und-gipser"

  [branche.treuhand]
    weight = 1
    name = "Maler und Gipser"
    description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iste deserunt, ducimus..."
    internal_link = "produkte/enterprise/maler-und-gipser"

  [branche.immobilienbewirtschaftung]
    weight = 2
    name = "Immobilienbewirtschaftung"
    description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iste deserunt, du`cimus..."
    internal_link = "produkte/enterprise/maler-und-gipser"

and tried to sort the data with .ByWeight and sort “weight” but nothing works. is it not supported or am I doing something wrong?

{{ $data := index .Site.Data .Site.Language.Lang }}
  
{{ range sort $data.products.erp_leafs.branche "weight" }}
  {{ .name }}
{{ end }}

can someone help me please?

thank you!
y

So, I don’t think that .ByWeight will not work since it is built to reference the weight field in the front matter of content files for your pages.

Can you try the following for me?

{{ $lang := index .Site.Data .Site.Language.Lang }}
{{ range $item, $params := sort ($.Site.Data.erp_leaftl) "weight" }}
    {{ if eq $lang $item }}
      {{ range $item }}
         {{.name}}
      {{ end }}
    {{ end }}
{{ end }}

This already looks ugly to me, so I think we might be able to accomplish this better with nested where statements. Do you have more of a repo to point me to by any chance?

hey rdwatters,
I just found that there was an error with my toml file.

removing the root [branche] solved the issue and I could sort the array by weight.
I don’t fully understand how toml arrays work yet, so this lead to the issue.

thank you for your response tho.

y

1 Like