There's no need for the outer foreach loop, unless you've got multiple news sections (even then, it's not really needed, depending on how you want to present the page). Also, trying to get descendants of children will fail - descendants is all you need as it includes children.
This example simply finds all NewsItems that are descendants of the homepage, and builds the list item accordingly. You'd probably see better performance by first finding the news index page, then getting it's descendant news items, especially if you had a large site with multiple children at the first level. Regardless, my example should get you what you need.
Playing around with razor
So, for a personal site, I have been playing around with Razor. But I'm totally not getting it yet.
I have the following structure:
website
news
year folder
month folder
news item
news item
month folder
news item
Now, I am trying to create a script, that will display all the news items on the front page. But for the life of me, I can't get it working.
What am I misunderstanding/doing wrong here?
-Ferdy
At it's most basic, try something like this, where NewsItem is the document type alias of your news items:
There's no need for the outer foreach loop, unless you've got multiple news sections (even then, it's not really needed, depending on how you want to present the page). Also, trying to get descendants of children will fail - descendants is all you need as it includes children.
This example simply finds all NewsItems that are descendants of the homepage, and builds the list item accordingly. You'd probably see better performance by first finding the news index page, then getting it's descendant news items, especially if you had a large site with multiple children at the first level. Regardless, my example should get you what you need.
That did the trick. Thanks!
-Ferdy
is working on a reply...