Copy link to clipboard
Copied
Hi,
We're working on a site with a very large database of events, and we've been trying to get them sorted using Liquid. We first tried a method similar to several mentioned here, such as creating a list of dates, and then looping through that list and only displaying the events on the date in question, or creating an array of dates and IDs and then doing an individual module_webapps call for each ID. These worked, but were incredibly slow. While trying to find a faster way, I reasoned based on experience with Liquid and module_data that using {% assign events = events | sort: "Date" -%} would work, and it does. This is mentioned in Shopify's Liquid docs, but it is not mentioned in BC's.
Is it safe to use this method? It's an order of magnitude faster and more elegant than any other method, but it's unmentioned by the docs and I don't want the client's site to suddenly break if this goes away or is modified.
Copy link to clipboard
Copied
Sort is Documented:
Filters | Business Catalyst Support
sort | {{ myArray | sort }} assuming myArray is an array ["5","4","3"] ]the sort filter outputs ["3","4","5"] |
BC only has the basic filter sort, not any of the more advanced stuff shopify has.
With what you did you had a date which is a numerical based value sorting an array of items you assigned.
This has a few problems.
1. You will find that as its a date not all items will actually sort properly, its a date not a number. So its not a proper sort.
2. You are only sorting the items in reference. BC can only load a max of 500 items so if you have a paged set that is 25 for example it is ONLY sorting those items and NOT the full blog post list. So your not sorting it all properly anyway.
The true sort comes from the tag or module you use. You can ignore the tag and use module_data and apply a sort there. By default in the overal layout blogs are sorted by date though.
So while it may look like it is working - best not to use this, it wont work properly.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now