Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I need to go through some CMSNodes and I'm trying to find the grandparent, under which an X number of nodes are present.
So I thought I would do something like node.Parent.Parent.. but I don't know how many parents there are...
I'm sure the answer is incredibly obvious, but I am completely blanking out here.
Sebastiaan,
You could use the Path property which specifies complete path for any given node. Or, use the Parent property and check for null (altho not sure if last method is useful)
Cheers,
/Dirk
Implement a recursive function for that. Do you need an example?
Thomas
Thanks guys, I was just having a brainfart, I implemented it this way:
CMSNode grandParent = new CMSNode(parentNode.Id); while (grandParent.Level > 1) { grandParent = grandParent.Parent; }
You can also use the Path value for that:
CMSNode grandParent = new CMSNode(int.Parse(parentNode.Path.Split(",".ToCharArray())[1]));
which takes the nodeId from the level 1 node of the actual node...
hth, Thomas
is working on a reply...
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.
Continue discussion
How do I loop through parent nodes
I need to go through some CMSNodes and I'm trying to find the grandparent, under which an X number of nodes are present.
So I thought I would do something like node.Parent.Parent.. but I don't know how many parents there are...
I'm sure the answer is incredibly obvious, but I am completely blanking out here.
Sebastiaan,
You could use the Path property which specifies complete path for any given node. Or, use the Parent property and check for null (altho not sure if last method is useful)
Cheers,
/Dirk
Implement a recursive function for that. Do you need an example?
Thomas
Thanks guys, I was just having a brainfart, I implemented it this way:
You can also use the Path value for that:
which takes the nodeId from the level 1 node of the actual node...
hth, Thomas
is working on a reply...
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.