I have a problem creating a foreach with children from 2 or more nodes.
There are 3 sites in one solution, and i need to show news from all sites on one of them.
There is no problem getting the content from one node but i can't find a solution for combining two or more nodes
You can use the SelectMany LINQ method if you've already got a set of the parent nodes, or you could possibly benefit from using the TypedContentAtXPath method on the UmbracoHelper.
For example:
foreach(var news in setOfParents.SelectMany(parent => parent.Children))
{
//...
}
or
foreach(var news in Umbraco.TypedContentAtXPath("//ParentDocType/ChildDocType"))
{
//...
}
Getting children of multiplenodes
I have a problem creating a foreach with children from 2 or more nodes. There are 3 sites in one solution, and i need to show news from all sites on one of them. There is no problem getting the content from one node but i can't find a solution for combining two or more nodes
You can use the
SelectMany
LINQ method if you've already got a set of the parent nodes, or you could possibly benefit from using theTypedContentAtXPath
method on theUmbracoHelper
.For example:
or
is working on a reply...