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?
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`.
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
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?
Something like this, perhaps:
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`.
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
Richard,
If you're within a RenderViewPage then you could possibly do something like this (untested):
Give that a shot and play around with it.
is working on a reply...