I want to define the sorting of pages in a list using a data file (therefor using a “string”), but have some issues.
{{ range .Pages }} is the default sort, I can also do {{ range (.Pages.ByParam $data_param) }}, and all is well… but what if I want to sort by ByExpiryDate, ByLength, or ByLinkTitle, which have no ByParam equivalent?
I tried {{ range (index .Pages "ByLength") }} or {{ range (index .Pages $data_by) }} but index doesn’t support methods/functions (?).
One solution would be to just spell out every .By* function in the template and call the appropriate one given the data string, but that’s allot more template code and it doesn’t automatically support every .By* function that may appear in Hugo at a later date. I could do this but perhaps there is a better solutions?
{{ if eq $data_by "ByLength" }}
{{ range .Pages.ByLength }}
...
{{ end }}
{{ else if eq $data_by "ByExpiryDate" }}
...