# Sorting associative arrays?

**URL:** <https://zola.discourse.group/t/sorting-associative-arrays/2907>\
**Category:** Support\
**Created:** [February 23, 2026, 11:10am UTC](https://zola.discourse.group/t/sorting-associative-arrays/2907 "2026-02-23T11:10:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BezPowell](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/bezpowell/32/604_2.png) [@BezPowell](https://zola.discourse.group/u/BezPowell)\
**Post date:** [February 23, 2026, 11:10am UTC](https://zola.discourse.group/t/sorting-associative-arrays/2907/1 "2026-02-23T11:10:15Z")

</div>

This is a question mainly to do with Tera, but could be relevant to Zola as well if the required functionality could be added there.

I’ve got a macro I use in multiple websites to build a little ‘metadata’ section on page listings.

```handlebars
{% macro meta(item) %}
<dl class="meta">
{% if item.date %}
    <dt>{{ trans(key="date") }}</dt>
    <dd>{{ item.date | date(format="%Y-%m-%d") }}</dd>
{% endif %}
{% if item.taxonomies %}
    {% for key, value in item.taxonomies %}
    <dt>{{ key | title }}</dt>
    <dd>{{ value | join(sep=", ") }}</dd>
    {% endfor %}
{% endif %}
</dl>
{% endmacro %}

```

This works well for quickly listing the taxonomies a page belongs to, but has one caveat: Taxonomies are not sorted. For example, if all pages in a section belonged to an author, and were part of several categories, one page might show the author first, while another might show categories first. E.g.

```handlebars
<ul>
    <li>
        <h2>Post 1</h2>
        <dl class="meta">
            <dt>Author</dt>
            <dd>Author 1</dd>
            <dt>Categories</dt>
            <dd>Category 1, Category 2</dd>
        </dl>
    </li>
    <li>
        <h2>Post 2</h2>
        <dl class="meta">
            <dt>Categories</dt>
            <dd>Category 2</dd>
            <dt>Author</dt>
            <dd>Author 2</dd>
        </dl>
    </li>
</ul>

```

I have tried sorting the taxonomy using `{% for key, value in item.taxonomies | sort(attribute=”key”) %}`, but this does not work in Tera. My question is: is there a way of sorting a HashMap / associative array in Tera, or would it be possible to change the way fields on a page are serialized to the template so that the order of properties is consistent (using something like `serde-ordered-collections`)?

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [February 24, 2026, 1:10pm UTC](https://zola.discourse.group/t/sorting-associative-arrays/2907/2 "2026-02-24T13:10:46Z")

</div>

> is there a way of sorting a HashMap / associative array in Tera

Not currently although it would be good to add a hashmap → vec filter in tera2 and then you can sort on the first field

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [February 24, 2026, 2:39pm UTC](https://zola.discourse.group/t/sorting-associative-arrays/2907/3 "2026-02-24T14:39:21Z")

</div>

[Add pairs filter by Keats · Pull Request #102 · Keats/tera2 · GitHub](https://github.com/Keats/tera2/pull/102) should solve the issue

---

<div class="post-metadata">

**Author:** ![BezPowell](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/bezpowell/32/604_2.png) [@BezPowell](https://zola.discourse.group/u/BezPowell)\
**Post date:** [February 24, 2026, 3:54pm UTC](https://zola.discourse.group/t/sorting-associative-arrays/2907/4 "2026-02-24T15:54:26Z")

</div>

Amazing. Thank you, keats!
