Question

Photo of Nate Barber

0

Lava Sort Descending

Lava Sort works well ... if you want to sort ascending. How can I set the sort to order Descending?

For example, this ascending sort works well:

{% assign children = Row | Children | Sort:'Age' %}

However, in the absence of documentation telling me how to do this, I tried several variations, none of which work:

{% assign children = Row | Children | Sort:'Age, desc' %}
{% assign children = Row | Children | Sort:'Age' Desc %}
{% assign children = Row | Children | Sort:'Age, descending' %}
{% assign children = Row | Children | Sort:'Age' Descending %}
{% assign children = Row | Children | Sort:'Age' Order:'Descending' %}

Is there no way to do this? Please help.





  • Photo of Nate Barber

    0

    After realizing that "lava" is simply the "liquid code language" for Rock, a brief yougoogily search reads that lava/liquid does NOT have a way to sort descending/reverse. What lava/liquid CAN do is execute a for loop in reverse. Sort an array ascending. Loop through it backwards.

    {% assign children = Row | Children | Sort:’Age’ %}{% for child in children reversed %}{{ child.FullName }}(Age{{ child.Age }}){% endfor %}

    • Jim Michael

      Good find I'll just add (for future visitors to this post) that there ARE parts of Lava that implement sorting, namely the Entity Commands I referenced in my first reply and can be seen here https://www.rockrms.com/page/746 (which can be confusing if you read "You can't sort in Lava" as that's not always true). Keep in mind that while Lava was originally based on Liquid, it has far surpassed it in certain ways for specific for Rock usage.

  • Photo of Jim Michael

    0

    Have you tried | Sort: ‘Age desc’ ? That’s the syntax for an Entity command sort, but you appear to be dealing with a metge document so I’m not sure if the syntax is the same there. 

  • Photo of Nate Barber

    0

    I think that was the first thing I tried, yes. Sorry I didn't include it up above. It returns the same as without the sort. No displayed error, but no sorting. Thanks for the thought.