Get Collection after traversing in Umbraco

649 views Asked by At

Here is my Project Folder Structure into Tree Structure

(*)Root
     []English
            [1]Novel
            [2]Thriller
                    [2.1]Happy
                              [2.1.1]Life Happy
                                           HappyInLife
                                           LoveInLife
                              [2.1.2]Joy
                                           everywhereJoy
                              [2.1.3]Lauging
                                           Always
                                           Sometimes
                                           Never
                    [2.2]Sad
                    [2.3]Excited
                    [2.4]Alone
            [3]Love Story
            [4]Action
     []Hindi
     []Marathi

Now here in the above structure I am at node [2.4]Alone and I want to traverse at node [2.1]Happy. Further I want to access all children , sub children and sub .... of node [2.1] Happy.

My Project requirement is to display the node [2.1]Happy along with all its children and sub children and so on.... from the node [2.4]Alone

My Work up till now (I am at node [2.4]Alone)

var [email protected]();

So home will have the node [2.1]Happy inside it. but the problem is it will give me only the children of [2.1]Happy and not its Children's children and so on...

I tired using @Model.AncestorsOrSelf(3); but not able to achieve my target .

Any help is appreciated

1

There are 1 answers

0
Dima Stefantsov On

I suggest using uQuery: (1) (2)

Code would look like:

@using umbraco

var current = umbraco.NodeFactory.Node.GetCurrent();
var your21Happy = current.Parent.GetChildNodes().First(); // or the way you was getting it already.
var descendants = your21Happy.GetDescendantNodes();

uQuery is pretty flexible, you can filter queried nodes by anything, like

.GetDescendantNodesByType("uBlogsyPost")

or

.GetDescendantNodes(x => x.WriterName == "admin")

etc.