Add sort_by support to people widget

This commit is contained in:
LoveSy 2025-02-22 02:15:00 +08:00 committed by GitHub
commit e2f7c290fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View file

@ -27,6 +27,13 @@
{{ range $block.Params.content.user_groups }} {{ range $block.Params.content.user_groups }}
{{ $query := where (where site.Pages "Section" "authors") ".Params.user_groups" "intersect" (slice .) }} {{ $query := where (where site.Pages "Section" "authors") ".Params.user_groups" "intersect" (slice .) }}
{{/* Sort */}}
{{ $sort_by := $block.Params.content.sort_by | default "Params.last_name" }}
{{ $sort_by = partial "blox-core/functions/get_sort_by_parameter" $sort_by }}
{{ $sort_ascending := $block.Params.content.sort_ascending | default true }}
{{ $sort_order := cond $sort_ascending "asc" "desc" }}
{{ $query = sort $query $sort_by $sort_order }}
{{if $query | and (gt (len $block.Params.content.user_groups) 1) }} {{if $query | and (gt (len $block.Params.content.user_groups) 1) }}
<div class="col-md-12"> <div class="col-md-12">
<h2 class="mb-4">{{ . | markdownify }}</h2> <h2 class="mb-4">{{ . | markdownify }}</h2>

View file

@ -17,6 +17,8 @@ content:
# Edit `user_groups` in each user's profile to add them to one or more of these groups. # Edit `user_groups` in each user's profile to add them to one or more of these groups.
user_groups: user_groups:
- Teachers - Teachers
sort_by: Params.last_name
sort_ascending: true
design: design:
show_interests: false show_interests: false
show_role: true show_role: true