I find this sort of thing a lot easier using the more strongly typed IPublishedContent instead of the dynamics because I get to use LINQ. I'd do something like this
@{
var currentPage = Model.Content;
var root = Umbraco.TypedContentAtRoot().FirstOrDefault();
}
foreach (var newsCat in root.Descendants().Where(n => n.IsDocumentType("NewsCategory") && n.Descendants().Any(d => d.IsDocumentType("NewsArticle"))))
{
}
Or maybe if you don't like the really long LINQ expression, you could do something like this:
@{
var currentPage = Model.Content;
var root = Umbraco.TypedContentAtRoot().FirstOrDefault();
}
foreach (var newsCat in root.Descendants().Where(n => n.IsDocumentType("NewsCategory")))
{
if(!newsCat.Descendants().Any(d => d.IsDocumentType("NewsArticle"))
{
continue;
}
}
Ah simple solution thanks to all, I thought I could do it in one for each but this works just as well without much fuss
@foreach(var newsCat in CurrentPage.Site().Descendants("newsCategory"))
{
if(newsCat.Descendants("newsArticle").Any()){
<li>@newsCat.Name</li>
}
}
How to call Children of a Certain page type, if their children have a certain page type....
Having trouble with this one basically I want to call a category name, only if it has descendants that have articles.
So I stared with this.
@foreach(var newsCat in CurrentPage.Site().Descendants("NewsCategory")) {
@newsCat.Name
}
But in natural language I would only want it to return a NewsCategory if that category had a descendant with a page type NewsArticle.
so for each Site NewsCategory where NewsCategory has Descendants named NewsArticle.
Thanks in Advance.
Doogie
I find this sort of thing a lot easier using the more strongly typed IPublishedContent instead of the dynamics because I get to use LINQ. I'd do something like this
Or maybe if you don't like the really long LINQ expression, you could do something like this:
May i ask why u use Descendants ? Your title indicates to me that u have a strukture like this
then u should not use Descendants use children instead, u will get a better preformance
if u have some other odd strukture with date folders u have to use Descendants
Aye its more like this
.
So I want to only call the category names if it happens to have news in it.
Thanks again
Doogie
is working on a reply...