[SOLVED ]Sort by a Param from Front Matter

Besides sorting by date and weight, can we sort by a Param from front matter? Ex:

first_name: "John"
last_name: “Smith”

I’d like to display all names from the person section and sort by last_name. The code below works, but it also displays blog posts because “sort .Data.Pages “Params.last_name”” is not part of the where condition.

{{ range sort .Data.Pages "Params.last_name" (where .Data.Pages "Section" "person") }}
    {{ .Params.last_name }}
{{ end }}

Maybe you’re looking for the GroupByParam func? RTD.

I’m pretty new to Hugo, but it seems to me you want to structure the range from the inside out. So,

{{ range sort (where .Data.Pages "Section" "person") "Params.last_name"  }}

3 Likes

That worked. Thanks
{{ range sort (where .Data.Pages "Section" "person") "Params.last_name" }}

1 Like