I’m currently trying to perform a custom sorting on a structure field. I want to build a page, which shows an overview of products grouped by their size.
So far, so good. I am just struggling with the sorting, because the size is given in letters (S, M, L, XL). Sorting them descending would work, if the XL size wouldn’t be there.
What’s the cleanest way to sort them, using the sortBy method?
The content in the file looks like this:
Products:
-
number: AM70
size: M
active: "1"
If there are multiple products, how can I order them so they appear in the correct ascending size (as mentioned, from S to XL)?
Another alternative would be to store the sizes as numbers (1,2,3) and then convert the numbers to letter sizes in your template using a category map. This would allow you to work with a collection (using the structure method) instead of working with an array.