Last active
September 17, 2024 00:58
-
-
Save primaryobjects/ab07cc7cac7e6480175fc995c022a7fc to your computer and use it in GitHub Desktop.
Jinja syntax to add a new property to sort a list by
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set updated_users = [] %} | |
{% for user in all_users %} | |
{% set names = user.full_name.split() %} | |
{% set first_name = names[0] %} | |
{% set last_name = names[1:] | join(' ') %} | |
{% set updated_user = user.copy() %} | |
{% set _ = updated_user.update({'first_name': first_name, 'last_name': last_name}) %} | |
{% set _ = updated_users.append(updated_user) %} | |
{% endfor %} | |
{% set sorted_users = updated_users | sort(attribute='last_name') %} | |
{% for user in sorted_users %} | |
{{ user.first_name }} {{ user.last_name }} | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment