var contentNode = Umbraco.TypedContent(item.Udi);
int childNodeCnt = contentNode == null ? 0 :
contentNode.Children().Count(c => c.IsVisible() && !c.Value<bool>("hideFromMenu"));
This takes advantage of full Linq statements, where as your v7 example is using dynamic linq which is no longer present in v8. It also adds in a check to make sure you get a content item back from the item.Udi line.
CS1061: 'UmbracoHelper' does not contain a definition for 'TypedContent' and no accessible extension method 'TypedContent' accepting a first argument of type 'UmbracoHelper' could be found (are you missing a using directive or an assembly reference?)
That would be because I was an idiot and forgot to update that line to be v8 compatible. Sorry about that. It should read:
var contentNode = Umbraco.Content(item.Udi);
Sorry about that. I'm also making the assumption that item.Udi is giving you the correct value that is expected by that method. I can't recall if it takes a UDI, or if you need to get the id/guid from it first.
I am getting this error.
CS1503: Argument 1: cannot convert from 'Umbraco.Core.Models.PublishedContent.IPublishedContent' to 'System.Collections.Generic.IEnumerable
Getting number of child nodes in Umbraco V8
I am trying to figure out how to check if a node has child nodes for a menu.
In v7 I had something like this.
The code for V7 does not work for v8 and I am not sure how to translate it.
try something like this
Hi Mov3nforward,
I would do something like this:
This takes advantage of full Linq statements, where as your v7 example is using dynamic linq which is no longer present in v8. It also adds in a check to make sure you get a content item back from the item.Udi line.
Hope that helps.
Nik
@Nik,
Your code throws an error.
CS1061: 'UmbracoHelper' does not contain a definition for 'TypedContent' and no accessible extension method 'TypedContent' accepting a first argument of type 'UmbracoHelper' could be found (are you missing a using directive or an assembly reference?)
That would be because I was an idiot and forgot to update that line to be v8 compatible. Sorry about that. It should read:
Sorry about that. I'm also making the assumption that item.Udi is giving you the correct value that is expected by that method. I can't recall if it takes a UDI, or if you need to get the id/guid from it first.
Nik
Thank you that works.
Now I am trying to pass to a helper the parent node so I can get the subpages to populate a dropdown menu.
/**********
I am getting this error. CS1503: Argument 1: cannot convert from 'Umbraco.Core.Models.PublishedContent.IPublishedContent' to 'System.Collections.Generic.IEnumerable
you probably need to do
you are just passing in a contentnode, but you want to pass in the children instead as your hepler is expecting a collection
is working on a reply...