However, I would like to limit the list of Children displayed to say 8, rather than display all.
I have also added a property DisplayDate (texstring) to the child doc type, which is of the form "Aug 2018", which I would like to sort the children on.
I have tried adding a counter, but whatever I do to break out of the foreach loop has failed so far. I have also tried using an indexed list and for loop without success too. I also tried adding all sorts of OrderBy clauses to my list and that failed too. I really am mega frustrated! Could someone enlighten me please or at least say it cannot be done!
Hi Paul, I don't think you really need a counter. You could just order your posts in ascending or descending, then "take" the first 8 for example.
Something like this might work for you.
@foreach (var post in CurrentPage.Children.OrderByDescending(x => x.GetPropertyValue<DateTime>("articleDate")).Take(8)) {
@post.displayDate
@post.Name }
Thanks very much for responding - your timing is immaculate as I have just got something to work.
I had to change my custom property to be a "date picker" (and then ToString("dd MMM yyy") to get my html), and also was getting super confused with the use (or lack of) the magical @! Sorry to have wasted your time - life is a learning experience .....
how to introduce counter and break into my foreach loop
Newbie so please be patient!
I have this code which works fine: @foreach(var post in CurrentPage.Children) {
@post.Name
@Umbraco.Truncate(post.Introduction, 240, true)
However, I would like to limit the list of Children displayed to say 8, rather than display all.
I have also added a property DisplayDate (texstring) to the child doc type, which is of the form "Aug 2018", which I would like to sort the children on.
I have tried adding a counter, but whatever I do to break out of the foreach loop has failed so far. I have also tried using an indexed list and for loop without success too. I also tried adding all sorts of OrderBy clauses to my list and that failed too. I really am mega frustrated! Could someone enlighten me please or at least say it cannot be done!
Thanks, Paul
Hi Paul, I don't think you really need a counter. You could just order your posts in ascending or descending, then "take" the first 8 for example. Something like this might work for you.
Thanks very much for responding - your timing is immaculate as I have just got something to work.
I had to change my custom property to be a "date picker" (and then ToString("dd MMM yyy") to get my html), and also was getting super confused with the use (or lack of) the magical @! Sorry to have wasted your time - life is a learning experience .....
is working on a reply...