This does what you want. If a person does not have a “status”, or if the “status” does not have a non-zero weight, that person will sink to the bottom of the list.
If the person front matter has two or more status values, we only consider the first. For example:
+++
title = 'Richard Doe'
status = ['mayor','ignored']
+++
layouts/persons/list.html
{{/* Create slice of maps, where each map contains the page and term weight. */}}
{{ $taxonomy := "status" }}
{{ $s := slice }}
{{ range .Pages }}
{{ $termWeight := 99999999 }}
{{ with (index (.GetTerms $taxonomy) 0).Weight }}
{{ $termWeight = . }}
{{ end }}
{{ $s = $s | append (dict
"page" .
"termWeight" $termWeight
)
}}
{{ end }}
{{/* Create a slice of pages, sorted by the term weight. */}}
{{ $p := slice }}
{{ range (sort $s "termWeight") }}
{{ $p = $p | append .page }}
{{ end }}
{{/* Render the page collection. */}}
{{ range (.Paginate $p).Pages }}
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a> ({{ index .Params.status 0 }})</h2>
{{ end }}
For example:
git clone --single-branch -b hugo-forum-topic-44820 https://github.com/jmooring/hugo-testing hugo-forum-topic-44820
cd hugo-forum-topic-44820
hugo server