All my content pages have a unique ID that consists of one letter and a number, e.g. D4. Ordering the pages using .ByParam (combined with .Reverse) works as expected:
A4
B5
C2
Now, if an ID has got a number with more than one digit, this obviously messes up the ordering, since the number is not treated as one integer, but instead as two individual characters (which is completely expected).
A1
A10
A11
A2
A3
I already came across the substr and int functions: {{ int (substr .Param.id 1) }} would return the number as an integer that Hugo could work with for ordering.
But how do I properly combine it with .ByParam?
Also, note that I still want the leading character to be considered as the “most significant bit”.
My idea was to use something like this:
{{ with (where (.Site.RegularPages.ByParam "id") "Section" "example") }}
{{ range sort . (int (substr .Params.id 1)) }}
{{ .Render "example" }}
{{ end }}
{{end}}
But this unfortunately returns: can't evaluate field Params in type page.Pages.
I mean, I could theoretically add the index number as a seperate page parameter, but that would mean certain (and kinda huge) additional efforts in other parts of the website. I’d like to avoid that – but if it’s the only option, I’d go for it. Though, I’d still need some advice on how to proceed then.
Good idea, but the ID is presented to the user and must therefore look “pretty”. However, it wouldn’t be too difficult to add a second, seperate ID which would only be used internally for that specific purpose.
(I’ll proceed with this work-around once I’m back at “work” tomorrow.)