Are child nodes included when added to a dynamic list?
I've created a dynamicNodeList to have a list of specific nodes. But after adding nodes to the dynamicNodeList. I have difficulties in fetching the child nodes (of the document type comments) - is this because child nodes are not included when added to the list or beacuse I'm new to Razor?
@* Get the followed nodes *@ @{ var homeNode = Model.AncestorOrSelf(1); DynamicNodeList followedNodes = new DynamicNodeList(); } @foreach (DynamicNode followedNode in homeNode.Descendants("ProcessSubprocess")) { @* check if the currentmember is included in the followerlist then add node*@ if (Library.NodeById(@followedNode.Id).followerList.InnerText.Contains(@currentMember)) { followedNodes.Add(followedNode); } } <ul> @foreach (DynamicNode item in followedNodes) { <li> @item.Name (@item.Comments.Count() comments) </li> } </ul>
I have no trouble getting the Name property, but only difficulties with the Children with @item.Name on the DynamicNode.
The first way returns:
Error loading Razor Script Object reference not set to an instance of an object.
The second way returns (also when I change "Items" to "Comments", which is the document type of the children):
'System.Collections.Generic.List' does not contain a definition for 'Comments' and no extension method 'Comments' accepting a first argument of type 'System.Collections.Generic.List' could be found (are you missing a using directive or an assembly reference?)
If I remove Comments (or Items) I get the Object reference not set to an instance of an object error.
'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'ChildrenAsList' and no extension method 'ChildrenAsList' accepting a first argument of type 'umbraco.MacroEngines.DynamicNodeList' could be found (are you missing a using directive or an assembly reference?)
Are "Items" then always used as a reference for nodes in the list?
@foreach(DynamicNode item in followedNodes) { // do your item code here @foreach(DynamicNode comment in item.ChildrenAsList.Items.Where(c => c.Visible && c.NodeTypeAlias == "YourNodeTypeAlias").OrderBy("CreateDate desc")) { //do something with the comment } }
Are child nodes included when added to a dynamic list?
I've created a dynamicNodeList to have a list of specific nodes. But after adding nodes to the dynamicNodeList. I have difficulties in fetching the child nodes (of the document type comments) - is this because child nodes are not included when added to the list or beacuse I'm new to Razor?
Hi
You can't can access documenttype properties directly on an DynamicNode object, only on a dynamic object. So you can change your code in 2 ways
Or
Thanks
I have no trouble getting the Name property, but only difficulties with the Children with @item.Name on the DynamicNode.
The first way returns:
Error loading Razor Script
Object reference not set to an instance of an object.
The second way returns (also when I change "Items" to "Comments", which is the document type of the children):
'System.Collections.Generic.List' does not contain a definition for 'Comments' and no extension method 'Comments' accepting a first argument of type 'System.Collections.Generic.List' could be found (are you missing a using directive or an assembly reference?)
If I remove Comments (or Items) I get the Object reference not set to an instance of an object error.
Any ideas of what I'm missing?
Sorry - I forgot that my member's login had timed out.
When removing "Items" from the second way it finally worked :o)
Moving on - I reached a new barrier - how do i list the Comments in followedNodes?
@foreach (DynamicNode item in followedNodes.ChildrenAsList.Comments.Where("Visible").OrderBy("CreateDate desc"))
does not seem to work
Try this :
Comments is not a property of a DynamicNodeList (this is what children as list returns)
So you would need something like
It doesn't seem to accept ChildrenAsList -
'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'ChildrenAsList' and no extension method 'ChildrenAsList' accepting a first argument of type 'umbraco.MacroEngines.DynamicNodeList' could be found (are you missing a using directive or an assembly reference?)
Are "Items" then always used as a reference for nodes in the list?
Oops my mistake...your code should be like this
I see, but that would separate the comments in individual nodes instead of getting a full list of comments from all nodes that I can sort.
The aim is to show the latest comments from specific followed nodes.
You can merge the into a new dynamic list and sort on that ?
Dave
Yes, good idea - which worked out well :o)
is working on a reply...