Skip to main content

sort_natural

array | sort_natural

Sorts the items in an array in case-insensitive alphabetical order.


Caution

You shouldn't use the sort_natural filter to sort numerical values. When comparing items an array, each item is converted to a string, so sorting on numerical values can lead to unexpected results.


{% assign tags = collection.all_tags | sort_natural %}

{% for tag in tags -%}
{{ tag }}
{%- endfor %}

Output

Burning
dried
extra-potent
extracts
fresh
healing
ingredients
music
plant
Salty
supplies
Anchor to Sort by an array item property

Sort by an array item property

array | sort_natural: string

You can specify an array item property to sort the array items by.

{% assign products = collection.products | sort_natural: 'title' %}

{% for product in products -%}
{{ product.title }}
{%- endfor %}

Output

Blue Mountain Flower
Charcoal
Crocodile tears
Dandelion milk
Draught of Immortality
Dried chamomile
Forest mushroom
Gift Card
Glacier ice
Ground mandrake root
Health potion
Invisibility potion
Komodo dragon scale
Love Potion
Mana potion
Potion beats
Potion bottle
Viper venom
Whole bloodroot
Was this page helpful?