Sorry for the double posting, getting desperate. Trying to list just the children of a specific node (Sectors, below), so content is like this:
Home - Sectors - - Sector1 - - Sector2 - - Sector3 - Other section - - stuff - - more stuff - Etc - - etc etc
and in a browser it looks like this:
Homepage content Sector1 | Sector2 | Sector3
I don't understand why I can query successfully for the node's title (Sectors):
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage var root = Model.Content.AncestorOrSelf(1); var sectionTitle = root.Descendants().Where(x => x.GetPropertyValue("title") == "Sectors");
but can't seem to get my claws on its descendants:
@foreach (var node in sectionTitle.Descendants()) { <p>@node.Name</p>}p>}
When I try to use that, it's not happy about putting 'Descendants' in that spot:
'System.Collections.Generic.IEnumerable<Umbraco.Core.Models.IPublishedContent>' does not contain a definition for 'Descendants' and the best extension method overload 'Umbraco.Core.Models.ContentExtensions.Descendants(Umbraco.Core.Models.IContent)' has some invalid arguments
although Descendants() works fine elsewhere, up above and in other versions/attempts.
Sorry for the slow reply. Kevin suggested in my other post in Razor, 'Retrieve children of a lower branch... ', to simplify my concept, which seemed like a good idea so I've been back at work and forgot to look here.
That said, until you mentioned it, I hadn't registered what IEnumberable and iPublishedContent really meant and now I've wandered off to look harder at those. It looks like iEnumerable is a C# thing for collections (expl), chiefly it enables the foreach loop, and iPublishedContent is an Umbraco thing for a (generally singel) content item ('Querying and Traversal' and 'Razor Feature Walkthrough 1'). I guess I'm not really getting what iPublishedContent is though.
I see 'Descendants()' on the v.6 cheat sheet is of the Collections group which would align with the C# info, and there's an item '.IsDescendant()' (singular) that references IPublishedContent. If I'd used IsDescendat() instead of Descendants(), would it have worked the same as your suggestion to add '.First()'? It can't be that simple... can it?
list children of a once removed node on homepage
Sorry for the double posting, getting desperate. Trying to list just the children of a specific node (Sectors, below), so content is like this:
Home
- Sectors
- - Sector1
- - Sector2
- - Sector3
- Other section
- - stuff
- - more stuff
- Etc
- - etc etc
and in a browser it looks like this:
Homepage content
Sector1 | Sector2 | Sector3
I don't understand why I can query successfully for the node's title (Sectors):
but can't seem to get my claws on its descendants:
When I try to use that, it's not happy about putting 'Descendants' in that spot:
although Descendants() works fine elsewhere, up above and in other versions/attempts.
Help?
Hello,
Your sectionTitle is an IEnumerable instead of a single IPublishedContent object. So try this:
Than it should be an IPublishedContent and Descendants should work.
Jeroen
Hello,
Did the above code worked for you?
Jeroen
Hi Jeron,
Sorry for the slow reply. Kevin suggested in my other post in Razor, 'Retrieve children of a lower branch... ', to simplify my concept, which seemed like a good idea so I've been back at work and forgot to look here.
That said, until you mentioned it, I hadn't registered what IEnumberable and iPublishedContent really meant and now I've wandered off to look harder at those. It looks like iEnumerable is a C# thing for collections (expl), chiefly it enables the foreach loop, and iPublishedContent is an Umbraco thing for a (generally singel) content item ('Querying and Traversal' and 'Razor Feature Walkthrough 1'). I guess I'm not really getting what iPublishedContent is though.
I see 'Descendants()' on the v.6 cheat sheet is of the Collections group which would align with the C# info, and there's an item '.IsDescendant()' (singular) that references IPublishedContent. If I'd used IsDescendat() instead of Descendants(), would it have worked the same as your suggestion to add '.First()'? It can't be that simple... can it?
Thank you much for the guidance. Love to learn.
is working on a reply...