Sort list by func(parameter)

I have a list of members, each with a name param like so:


name: Abe Lincoln


name: George W. Bush


{{ 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:

<>: 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/, and also change to `{{ range .Data.Pages }}, but I’d like to avoid that if possible.

My questions:

  1. Is this type of sorting supported by Hugo’s template syntax?
  2. Is my workaround of re-naming files a reliable way of achieving my desired sort order?
  3. Is there any other way I can achieve this sort order without having to add additional parameters?


Drop the “sort” function call, which is superflous.

Dropped, and tested with and without prior to posting.