I want to sort a collection ($paginator.Pages in my case) by a value derived by aggregating a Param: score for all Pages with that Title. So
Created a partial function that returns the aggregated value across all pages with the same Title
I then use Store.Set to attach the aggregated value returned by the partial to each Page like this
{{ range $paginator.Pages }}
{{ .Store.Set "totalScore" (partial "score-aggregator.html" .LinkTitle) }}
{{ end }}
Finally I use the following expression
{{ range sort $paginator.Pages (.Store.Get "totalScore") "desc" }}
{{/* do something with each page */}}
{{ end }}
While I get no errors, the sort order is clearly incorrect. Can someone help with what I am doing wrong? I have confirmed that the partial returns the correct value.
For this one the context is the current page, so that won’t work.
i could think of to using a map in your first loop and store all pages with score as key
score = page (or pages if the score is not uniq)
then sort the map by score which will remove the key and leave the page(s) for each score.