Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Sort taxonomylist

Started by Muut Archive 10 years ago · 4 replies · 896 views
10 years ago

Hey everyone,
I need to arrange my taxonomylist alphabetically. I found older forumposts mentioning the ksort function, but it seems not to work anymore. Also found something about the sort_by_key function and tried that, but I think I'm not doing it correctly. Could you help out? Here is my code:

TWIG
{% set taxlist = taxonomylist.get() %}
{% if taxlist %}
  {% set category = grav.uri.params("category", true) %}
  {# for tax,value in taxlist['category']|sort_by_key('tax') #}
  {% for tax,value in taxlist['category']|ksort %}
    {% set current_page = (tax == category) ? 'active' : '' %}
    <li class="">
      <a href="{{ page.url }}/category{{ config.system.param_sep }},{{ tax|e('url') }}">{{ tax|capitalize }}</a>
    </li>
  {% endfor %}
{% endif %}

Thanks in advance!

10 years ago

Hey, is there anyone who knows how to deal with this issue? Thanks a lot in advance :)

10 years ago

Your sort command is commented out. Does it work as expected when active?

10 years ago

@Bob, I added both the options I tried. Both did not work 😒

10 years ago

I'm using a sort of this form:

{% for tag in page.taxonomy.tag|sort %}

Suggested topics

Topic Participants Replies Views Activity
Archive · by Muut Archive, 10 years ago
1 672 1 week ago
Archive · by Deleted User, 9 years ago
0 3042 9 years ago
Archive · by Muut Archive, 9 years ago
2 1983 9 years ago
Archive · by Muut Archive, 9 years ago
2 5336 9 years ago
Archive · by Muut Archive, 9 years ago
1 4134 9 years ago