Hi,
I would like the ability to order block items (ContentAreaItem) within a content area by published date (StartPublish). I am adding a new bool 'Order Items' to the model and if true I want to apply the order as opposed to the default sort order in which content has been created within the content area.
From my initial look it seems that i need to cast the ContentAreaItem to an IVersionable in order to access the StartPublish value. I achieved this as follows, it returns an IEnumerable<IVersionable> collection (The reason for loading 'BlockData' is becausethere are three different types that are allowed to be created)
var items = block.ContentItemArea.FilteredItems.Select(i => contentLoader.Get<BlockData>(i.ContentLink) as IVersionable);
if (block.OrderItems)
{
items = items.OrderByDescending(x => x.StartPublish);
}
What is the best way to cast an IVersionable type back into a ContentAreaItem so that i can add them into a ContentArea and use the @HtmlPropertyFor helper in the view to render the items out ? One thing i looked at was loop through the items in the IVersionable collection and using new ContentAreaItem() { ContentGuid = item.ContentGuid, ContentLink = item.ContentLink }; but i am unsure if this is the correct approach.
Im hoping i have missed something obvious and there is a straight forward way of achieveing this :)
Thanks
Paul