-
Notifications
You must be signed in to change notification settings - Fork 373
Sort foundation members alphabetically in display #2763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this is good so far. If you check the current manual ordering, notice that we order the entries irrespective of capitalization. Could you add that as well?
Thank you for the suggestion! I attempted to implement case-insensitive sorting in the Tera template to match the current manual ordering (ignoring capitalization). Here are the approaches I tried: Attempt 1: Just applies lower to the string "name", not the actual values. Attempt 2: Inline dictionary creation with concat
Error: expected a value that can be negated Attempt 3: Create a dictionary using set
Error:expected a value that can be negated or an array of values Tera doesn’t support setting dictionaries directly inside templates. What would be the best way to proceed? |
Sorry, this turned out to be trickier than expected. Ideally, Tera would simply support a flag for sorting case-insensitively. This is not the case but looks to be on the horizon: Keats/tera#967. We should migrate to it as soon as it becomes available, but that is not today. Your ideas are good, Tera is just pretty limiting, and even more so since we can't just extend its filters as we need it compiled into Zola. Sadly, The second attempt is also good, but as you figured out in attempt 3 Tera doesn't support creating "dictionaries" ad-hoc. We have to dig deep in our box of tricks. To be sure if this is possible at all, I had to implement it and find a working solution. Here is what I came up with plus some explanations. Some variable names are not yet ideal: {# we create an array of only the supporter names in lower case so we may sort it later #}
{% set lower_supporters = [] %}
{% for lower_supporter in supporters.silver | map(attribute="name") %}
{% set_global lower_supporters = lower_supporters | concat(with=[lower_supporter | lower ]) %}
{% endfor %}
{% for lower_supporter in lower_supporters | sort %}
{# we search the original supporter object that matches our lower-cased name #}
{# this is not ideal since we blow up the complexity up to O(n^2) but I don't see another way #}
{% for supporter in supporters %}
{# note the order of operators #}
{% if supporter.name | lower == lower_supporter %}
{% set_global current_supporter = supporter %}
{% break %}
{% endif %}
{% endfor %}
{# we can now use the supporter object #}
<a href="{{ current_supporter.website }}" target="_blank" class="supporters-card">
<img src="/support/{{ current_supporter.logo }}" alt="{{ current_supporter.name }}'s logo">
<span>{{ current_supporter.name }}</span>
</a>
{% endfor %} If you would like to continue, can you clean that up a bit and create a macro for that next to our other macros in /templates/macros/ so we don't have to maintain copies of this code? nominee.html should be a good example of how to do it. |
Resolves(#2756 ) Thanks for the detailed breakdown! This turned out to be a great learning opportunity I gained a much better understanding of Tera’s limitations and some creative ways to work around them, especially regarding sorting and macro structuring. I’ve taken your suggestion and implemented the workaround as a macro in /templates/macros/supporters.html, inspired by the structure in nominee.html. I also refactored the main support.html file to use the macro. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, thanks again!
Solves Issue (#2756 )
This PR updates the Tera template to sort Foundation members alphabetically by name within each tier (Platinum, Gold, Silver, etc.) during rendering. The supporters.toml file remains unchanged.
Thank you for the clarification! I've implemented the sorting directly in the Tera template as suggested. Let me know if any changes are needed.