Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • rob 75 posts 170 karma points
    Nov 28, 2013 @ 11:21
    rob
    0

    How to get a node by name n levels down in v6.0.2?

    If I use ApplicationContext.Current.Services.ContentService.GetChildrenByName(NodeId, "NodeName");

    It can only find nodes directly under NodeId.

    What options have I got for finding nodes by name in the tree at any level under NodeId?

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Nov 28, 2013 @ 11:46
    Tim
    0

    Hi Rob,

    Are you doing this on the front or back end of the site? If you're in the front end, DON'T use the ContentService, as it hits the database, use the ContentCache instead, which will allow you to do the type of query that you're after!

    Can you give me a bit of information about where in your application you're trying to query the nodes (front end or back office etc), and I'll see if I can give you some example code!

  • rob 75 posts 170 karma points
    Nov 28, 2013 @ 12:06
    rob
    0

    I am using it on the front end, example code would be welcome.

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Nov 28, 2013 @ 15:26
    Tim
    0

    I'll assume you're using a Razor Macro or MVC view, in which case, something like this should do the trick for you:

    Umbraco.TypedContent(NodeId).Descendants("DocumentTypeAliasHere")
    

    Will get you all of the descendants of the node with the id you pass in with the document type alias that you pass in to the Descendants function.

    If you want to get the nodes by the actual text name of the nodes, you could try:

    Umbraco.TypedContent(NodeId).Descendants().Where(a => a.Name = "NODE NAME HERE")
    

    There's some documentation on querying content on the front end here:

    https://github.com/umbraco/Umbraco4Docs/blob/master/Documentation/Reference/Templating/Mvc/querying.md

    Hope that helps!

    :)

Please Sign in or register to post replies

Write your reply to:

Draft