Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I am trying to get the descendants of a node where the nodeTypeAlias exists as an entry in a string array that may have a variable number of entries.
Does anyone have any ideas about how to do this?
Thanks,Mike
I got the following to work. I put the nodes and aliases into Lists so I could use the IEnumerable methods, Where and Any. Just set the root to whatever node you want.
@using umbraco.MacroEngines@inherits DynamicNodeContext@try{ dynamic root = Library.NodeById(-1); DynamicNodeList list = root.Descendants(); List<DynamicNode> descendants = new List<DynamicNode>(list.Cast<DynamicNode>()); List<string> aliases = new List<string> {"umbHomepage", "umbTextpage"}; var filtered = descendants.Where(n => aliases.Any(a => a == n.NodeTypeAlias)); <ul> @foreach (var node in filtered) { <li>@node.Name</li> } </ul>}catch (Exception e){ @e.ToString() }
Hi Douglas,Personally I'd use the following to populate filtered:
var filtered = descendants.Where(n => aliases.Contains(n.NodeTypeAlias));
To me, it looks a little cleaner, but your answer is completely valid.
Jamie
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Get descendants where nodeTypeAlias in array
I am trying to get the descendants of a node where the nodeTypeAlias exists as an entry in a string array that may have a variable number of entries.
Does anyone have any ideas about how to do this?
Thanks,
Mike
I got the following to work. I put the nodes and aliases into Lists so I could use the IEnumerable methods, Where and Any. Just set the root to whatever node you want.
Hi Douglas,
Personally I'd use the following to populate filtered:
To me, it looks a little cleaner, but your answer is completely valid.
Jamie
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.