Copied to clipboard

Flag this post as spam?

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


  • Richard Brookes 34 posts 57 karma points
    May 22, 2012 @ 13:23
    Richard Brookes
    0

    5.1 Get Siblings of root node

    I have several root level nodes in my 5.1 site. Can anybody tell me how I can list the nodes under one root level node from a page under a different tree?

  • Grant Thomas 291 posts 324 karma points
    May 22, 2012 @ 13:38
    Grant Thomas
    0

    Something like this, perhaps:

    var aRootApart = Umbraco.GetContentById(anIdForTheNode);
    if (aRootApart != null) {
      var aRootApartChildrenIds = aRootApart.AllChildIds(); 

    Couple of notes. You say "siblings" but refer to "children" (i.e. "under a node") - which should it be, since siblings of a root node would be other root nodes? When using Umbraco.Cms.Web.Model.Content to harness the xxxIds methods then you can get 'bad' data back; that is, `GetContentById` can return null because the Ids can contain those referencing no longer published (or even no longer existing) content.

    Lastly, I use `AllChildIds` yet I have no idea if that actually exists; it should be exposed as an extension method but I can't recall the type, can't find the source file nor documentation. It will be something of this sort. You could also, of course, use `GetDynamicContentById` and use `Children`.

  • Richard Brookes 34 posts 57 karma points
    May 22, 2012 @ 23:08
    Richard Brookes
    0

    Thanks for the reply Grant. Your answer has helped me move on. I will clarify what I am trying to achieve

    Here is the structure

    -Content

        -Root 1

            -Root1 Node 1

        -Root 2

            -Root 2 Node 1

            -Root 2 Node 2

    From within Root 1 Node 1 I want to list the contents of Root 2. i.e. the contents of the sibling of the root node for the tree I am currently in.

    I have been able to do this using the answer above but this requires me to know the id of Root 2. Ideally I would be able find this using the alias or perhaps do the same thing with yet another root node i.e. Root 3

     

  • Grant Thomas 291 posts 324 karma points
    May 22, 2012 @ 23:35
    Grant Thomas
    0

    Richard,

    If you're within a RenderViewPage then you could possibly do something like this (untested):

    var matches = Hive.QueryContent().Where(c => c["someAlias"] == "someAliasValue");

    Give that a shot and play around with it.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies