Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Sort taxonomylist

Started by Muut Archive 9 years ago · 4 replies · 636 views
9 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!

9 years ago

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

9 years ago

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

9 years ago

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

9 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 Deleted User, 9 years ago
0 1323 9 years ago
Archive · by Muut Archive, 9 years ago
2 919 9 years ago
Archive · by Muut Archive, 9 years ago
2 4048 9 years ago
Archive · by Muut Archive, 9 years ago
1 2923 9 years ago
Archive · by Muut Archive, 9 years ago
3 1106 9 years ago