I have a list of members, each with a name
param like so:
content/members/abe.md
name: Abe Lincoln
content/members/bush.md
name: George W. Bush
layouts/members/list.html
{{ range sort .Data.Pages.ByParam "name" }}
{{ .Params.Name }}
{{ end }}
I’d like to sort them in a list by last name, but I can’t (read: don’t want to) define a separate parameter for last name, so I was hoping I could do something simple such as split the name
parameter, and take the last element. Something like this perhaps:
{{ range sort (last 1 (split (.Data.Pages.ByParam "name") " ")) }}
However, that doesn’t work and spits out the following error:
<.Params.name>: can't evaluate field Params in type string
The only workaround (other than defining an additional param) that I’ve found is to rename my files: content/members/lincoln.abe
and content/members/bush.george.w
, and also change to `{{ range .Data.Pages }}, but I’d like to avoid that if possible.
My questions:
- Is this type of sorting supported by Hugo’s template syntax?
- Is my workaround of re-naming files a reliable way of achieving my desired sort order?
- Is there any other way I can achieve this sort order without having to add additional parameters?
Thanks!