I'm using a simple foreach loop to recieve all the child items and than filter them by Alias:
@foreach (var work in CurrentPage.Children)
{
if (work.ContentType.Alias == "work")
{
<p>@work.sortNumber</p> // numeric-field adjustable by customer
}
}
I'm looking for a simple solution to sort the work collection by the work.sortNumber field. I think I came close to a solution but without a working result:
foreach (var item in Model.Content.Children.Where(x => x.ContentType.Alias == "work").OrderBy(t => t.GetPropertyValue("sortNumber"))) {
foreach (var property in item.Properties){
// Cannot find a way to get the needed properties, and is this even a good way to do this?
}
}
Order child-items by custom numeric-field
I'm using a simple foreach loop to recieve all the child items and than filter them by Alias:
I'm looking for a simple solution to sort the work collection by the work.sortNumber field. I think I came close to a solution but without a working result:
Any help would be appreciated!
Hi Sam
In your loop you can read properties like so:
@item.GetPropertyValue("workSortOrder")
or
@item.GetPropertyValue<int>("workSortOrder")
If you need to cast the property to a type
I removed the inner foreach and replaced it with your suggested line of code: @item.GetPropertyValue("propertyValueNames") and it worked! Thanks.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.