I have a multisite installation, and I want to make a collection that contains all the 'news' nodes of all the sites so that I can display news from each site on the 'master' site. Eg...
var collection1 = CurrentPage.Descendants("NewsPageSite1").OrderBy("publishDate desc");
var site2 = Umbraco.ContentAtRoot().Last();
var collection2 = site2.Descendants("NewsPageSite2").OrderBy("publishDate desc");
var comboCollection = collection1 + collection2;
foreach( var node in comboCollection ) {
@* dostuff *@
}
Is this possible? And, if so, how can I order the new, combined collection?
Also, is there a way I can get the site nodes other than Umbraco.ContentAtRoot().First() and .Last() - which obviously limits me to the first and the last node?
One more thing. I need to be able to get the various collections, ideally by somehow referencing the site nodes by name, eg:
var collection1 = Umbraco.ContentAtRoot().First().Descendants("NewsPageSite1").Where("Visible");
var collection2 = [ site node named eg "Site 2" ].Descendants("NewsPageSite2").Where("Visible");
var collection3 = [ site node named eg "Site 3" ].Descendants("NewsPageSite3").Where("Visible");
var collection4 = Umbraco.ContentAtRoot().Last().Descendants("NewsPageSite4").Where("Visible");
Getting the first and last site nodes is easy enough, but how can I get the 2nd, 3rd, etc – particularly as I may want to get just 1, 2 and 4 or 1 and 3 etc.
Combine collections with Razor
I have a multisite installation, and I want to make a collection that contains all the 'news' nodes of all the sites so that I can display news from each site on the 'master' site. Eg...
Is this possible? And, if so, how can I order the new, combined collection?
Also, is there a way I can get the site nodes other than Umbraco.ContentAtRoot().First() and .Last() - which obviously limits me to the first and the last node?
Thanks
Hi Robin,
You can use .Concat() or .AddRange() methods for combining lists.
http://stackoverflow.com/questions/4488054/merge-two-or-more-lists-into-one-in-c-sharp-net
Thanks
Thanks, Alex – very helpful and has done the trick!
One more thing. I need to be able to get the various collections, ideally by somehow referencing the site nodes by name, eg:
Getting the first and last site nodes is easy enough, but how can I get the 2nd, 3rd, etc – particularly as I may want to get just 1, 2 and 4 or 1 and 3 etc.
Thanks
is working on a reply...