I've using a matrix field from the same entry in two different templates. In one template I want them in the order they're displaying in the CMS, while in the other I want them displayed in reverse.

It doesn't like this:

{% for cta in entry.ctas.order('desc') %}

Can this be done any other way?


I went and looked at the MatrixBlockModel; there's an attribute named sortOrder (If you output {{sortOrder}} inside the for loop, it will display the index of that block).

You can use that attribute to sort by, in reverse:

{% for cta in entry.ctas.order('sortOrder desc') %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.