How do we get a specific node after iterating through the child nodes? | Community
Skip to main content
Level 4
April 13, 2022
Solved

How do we get a specific node after iterating through the child nodes?

  • April 13, 2022
  • 3 replies
  • 1167 views

Iteration for all the child nodes is don and I'm trying to get a specific node name and return the property value of that node.

while (children.hasNext()) {
Page node = children.next();
Iterator<Page> child2 = node.listChildren(new PageFilter(request));
Page node2 = children2.next();
while (children2.hasNext()) {
Page node2 = child2.next();
---?


 

 I need only one node from the child of first node of first level

A

   a

   b

   c

B

   d

   e

   f

C

  g

  h

  i

 

I want to print only b from A and the rest should remain as it is. I'm trying the back end logic because the hideInNav page property hides all the navgation of that page and I want it to be hidden only from footer and not anywhere else.

A     B     C

 

b       d     g

         e      h

         f        i

         f

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

Get all pages(at all level) or Get immediate children pages

listChildren(Filter<Page> filter, boolean deep)

 

Get immediat page with name

If(page.getParent().hasChild('another-sibling-page')){
page.getPageManager().getContainingPage(another-sibling-page')
}

 

 

Get page Property

ValueMap getProperties()

 

3 replies

Ravi_Pampana
Community Advisor
Community Advisor
April 13, 2022

Hi,

 

How are you identifying that you need (b from A), (d,e,f from B), (g, h, i from C) ?

 

If there is specific property in node, you can check for that property and value while iterating the child nodes.

 

or you can add a new property which needs to be visible and based on that property you can filter the nodes.

DEBAL_DAS
April 14, 2022

Let's assume that I do have below page taxonomy or content hierarchy -

Here we could see resource named: Equipment is having [/content/we-retail/language-masters/en/products/equipment] is having children like Surfing, Running, Water Ports and so on.

Now if I want to read resource named: The Stretch Longboard which is one of child of Surfing as shown below -

 

Then I could create a node object for Equipment and 

 

Node euipmentNode = your logic to read node object associated with page named: Equipment

if(euipmentNode.hasNode('surfing')){

  Node surfingNode = euipmentNode.getNode('surfing');

   if(surfingNode.hasNode('the-streach-longboard')){

         Node streachNode = surfingNode.getNode('the-streach-longboard');

     // add logic to read property of streachNode

    }

}

 

This is one approach came to my mind and please review.

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
April 14, 2022

Get all pages(at all level) or Get immediate children pages

listChildren(Filter<Page> filter, boolean deep)

 

Get immediat page with name

If(page.getParent().hasChild('another-sibling-page')){
page.getPageManager().getContainingPage(another-sibling-page')
}

 

 

Get page Property

ValueMap getProperties()

 

Arun Patidar