Recipe - Sort Content Channel Child Items by StartDateTime
Skill level: Intermediate
Organization: Fishhook
Requires Rock: 1.5.0
{# strip images & classes from the HTML but otherwise leave structure #}
As we were building a Sermon Series layout, using a Parent content channel for Series and a Child content channel for Sermon items, it became apparent that there wasn't an easy way to affect the order that child items were returned.
The demo site on Rock uses a "Content Channel View Detail" Block to display Series information with a URL query parameter, but that Block currently doesn't support Rock Entities, so I rebuilt the content for the Series on that page with a "Content Channel View" Block, and a contentchannelitem entity to loop through and sort child items by Start Date in descending order (newest first).
@brian at NewSpring helped me with the attached Lava
<ol class="messages">
{% capture childIds %}
{% for child in Item.ChildItems %}
Id == {{ child.ChildContentChannelItem.Id }}{% unless forloop.last %} || {% endunless %}
{% endfor %}
{% endcapture %}
{% contentchannelitem where:'{{ childIds }}' sort:'StartDateTime desc' %}
{% assign sortedItems = contentchannelitemItems | Sort:'StartDateTime desc' %}
{% for message in contentchannelitemItems %}
<li>
{{ message.Id }}: <a href="/page/461?Item={{ message.Id }}">
{{ message.Title }}
</a> - {{ message.StartDateTime }}
</li>
{% endfor %}
{% endcontentchannelitem %}
</ol>
Download related file (SeriesDetailwithSortedChildItems.txt)
Screenshots
- /GetImage.ashx?guid=f4076a92-b1d4-4a07-a304-9a284d473b36