3

I can see that Liquid allows you to sort a collection using the below syntax:

{% assign sorted_items = items.all|sort:'Email' %}

{% for item in sorted_items %}
  <div>Name: {{item.name}}</div>
  <div>Email: {{item.email}}</div>
{% endfor %} 

However this does not appear to work in Business Catalyst.

If I use this to render the result to the page it simply renders "null".

{{sorted_items | json }}

Should I be able to do this in Business Catalyst, or am I completely wasting my time trying to find a solution to sort my WebApp data?

David
  • 159
  • 1
  • 3
  • 13
  • Looks like it's not implemented, per this discussion on the BC forums: https://forums.adobe.com/thread/1711721 – Robert K. Bell Sep 15 '15 at 11:41
  • This question could be improved to include "Web App" as part of the question, e.g. "Business Catalyst Liquid Sorting Web App Items". It isn't immediately clear what data you're trying to sort. Are you trying to sort web app data by email address alphabetically? Because "alphabetically" isn't included anywhere in your question either... – Luke Oct 30 '16 at 21:09

2 Answers2

0

You can sort the data like this:

{module_data resource="customers" version="v3" fields="firstName,email1" collection="myData"}
<pre>{{myData|json}}</pre>

{% capture emails -%} 
{% for item in myData.items -%}
,{{ item.email1.value }} - {{ item.firstName }};
{% endfor %}
{% endcapture %}
<pre>{{ emails | split: "," | sort }}</pre>

The comma is not spelling mistake : )

After you split the string in array you can do whatever you need to do with it.

Daut
  • 2,537
  • 1
  • 19
  • 32
0

The answer from Daut is not good. Any solution in the for loop will only sort the number of items fetched from the module and the max amount for that is 500. If you are using module_data you just use its actual sort!

{module_data resource="customers" version="v3" order="firstName" fields="firstName,email1" collection="myData"}

module_data supports both WHERE for filtering and ORDER to order the results.

thenexus00
  • 22
  • 5
  • How do you order was asked. module_data and a loop filter given. That will not work. I stated why and gave the actual solution through the user order option in the module. So that is very much the answer. – thenexus00 Oct 16 '16 at 22:55