1
votes

I'm on version 3.8.4. Say I have made an array that I want to print in reverse order:

{% assign words = 'swag, yolo, hi' | split: ", " | sort: 'last' %}

{% for word in words %}

    <p>{{word}}</p>

{% endfor %}

Even with sort: 'last', this will print as:

swag
yolo
hi

Maybe it's 'first'. The output is still

swag
yolo
hi

with 'first'.

I've been trying to sort a collection in Jekyll by some page front-matter, and sort works--it lists everything in order, by the numbers I gave them (not by title or date), first to last, but what if I want it last to first? If I sort: 'last', it's still sorted first to last. Is the last option broken? Am I doing something wrong?

Here's a screenshot: https://i.imgur.com/7Fxep9A.png

1

1 Answers

2
votes

It looks from the docs like sort always goes one way. The argument you pass to it is the name of the property to sort on. Your objects don't have properties named 'first' or 'last', so it's being ignored.

To get what you want, just use sort to sort a-z, and then reverse to reverse the sorted list (z-a): {% assign words = 'swag, yolo, hi' | split: ", " | sort | reverse %}