Hello,
I’m trying to sort a set of pages by a value I set in the pages’ Scratch variable and not having any luck
To give a bit more context ~
My template has a bunch of boolean values that I’m summing into the pages’ scratch as a variable I’m calling score
.
I can see that score
is set properly with the following:
{{ .Scratch.Get "score" }}
~ returns a number (score) eg: 1,3,4, whatever
Now I need to sort pages by this score but I’m having no luck.
I’ve tried ~
Using byParam:
{{ range $pages.byParam (.Scratch.Get "score") }}
Doesn’t work because I think this would try to sort by a param named 1,2,3 etc…
Using sort:
{{ range sort $pages (.Scratch.Get "score") }}
Again, same thing… I’m thinking it’s looking for a param that doesn’t exist.
Creating a map in Scratch and sorting the map:
$.Scratch.SetInMap "pages" (.Scratch.Get "score") .
$pages := $.Scratch.GetSortedMapValues "pages"
This sort of works ~ I get back ordered pages that I can sort but since I’m using the score as the key and multiple items have the same score I’m overwriting some of the values. I can continue to explore this avenue but it seems very complicated.
This seems like it shouldn’t be so hard, but maybe I’m missing something? Is there a way to sort pages by a compile time calculated value?