Hi guys, sorry I didn't reply straight away, was very busy with another project. Thanks for you answers but unfortunately I can't make to work neither of them.
When I try
using umbraco.presentation.nodeFactory; ... Node parent = uQuery.GetCurrentNode().Parent; List nodes = parent.GetChildNodesByType("MyDocType");
It can't build it, I get this error:
'umbraco.presentation.nodeFactory.Node' does not contain a definition for 'GetChildNodesByType' and no extension method 'GetChildNodesByType' accepting a first argument of type 'umbraco.presentation.nodeFactory.Node' could be found (are you missing a using directive or an assembly reference?)
dynamic model =new umbraco.MacroEngines.DynamicNode(umbraco.NodeFactory.Node.GetCurrent()); var node = model.Parent.Descendants("MyDocType")
doesn't build as well. I get:
The type or namespace name 'DynamicNode' does not exist in the namespace 'umbraco.MacroEngines' (are you missing an assembly reference?) Also it doesn't like model.Parent part : One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll?
Which dlls do I need to reference? I added umbraco, cms, interfaces, businesslogic to my projects.
Node current = new Node(Node.GetCurrent().Id); Node parent = new Node(current.Parent.Id); Nodes siblings = parent.Children; foreach (Node node in siblings){ if (node.NodeTypeAlias == "somedoctype") { do stuff }}
Not at all tested, but I have done something similar in the past to populate a dropdown ;) uQuery is probably a bit more tidy.
Traversing nodes in C#
Hi guys, sorry if such question was already answered here, I can't find the solution.
I need to get parent's children of particular document type. In razor (4.7.2) I can do it like this:
@Model.Parent.Descendants("MyDocType")
I know I can use uQuery to get all nodes of type:
List<Node> allNodes = uQuery.GetNodesByType("MyDocType");
That will return all nodes, but I need only parent's children. How can I do it?
Thanks.
You can also use that Razor example in C#, but you first need to get the model:
Jeroen
Hi Zakhar,
or how about:
Hendy
Hi guys, sorry I didn't reply straight away, was very busy with another project. Thanks for you answers but unfortunately I can't make to work neither of them.
When I try
using umbraco.presentation.nodeFactory;
...
Node parent = uQuery.GetCurrentNode().Parent;
List nodes = parent.GetChildNodesByType("MyDocType");
It can't build it, I get this error:
'umbraco.presentation.nodeFactory.Node' does not contain a definition for 'GetChildNodesByType' and no extension method 'GetChildNodesByType' accepting a first argument of type 'umbraco.presentation.nodeFactory.Node' could be found (are you missing a using directive or an assembly reference?)
doesn't build as well. I get:
The type or namespace name 'DynamicNode' does not exist in the namespace 'umbraco.MacroEngines' (are you missing an assembly reference?)
Also it doesn't like model.Parent part :
One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll?
Which dlls do I need to reference? I added umbraco, cms, interfaces, businesslogic to my projects.
Thanks,
Zakhar
Hi Zakhar,
Sorry, for the uQuery example above, you'll need:
HTH,
Hendy
Not at all tested, but I have done something similar in the past to populate a dropdown ;) uQuery is probably a bit more tidy.
Hi Zakhar,
For DynamicNode you need to add a reference to the umbraco.MacroEngines.dll file.
Jeroen
is working on a reply...