Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

[AEM Gems Webinar] Accelerating Experience Manager as a Cloud Service development with Rapid Development Environments
SOLVED

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

Avatar

Level 3

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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()

 

View solution in original post

3 Replies

Avatar

Community Advisor

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.

Avatar

Community Advisor

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

DEBAL_DAS_1-1649904506623.pngDEBAL_DAS_2-1649904630492.png

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 -

DEBAL_DAS_3-1649905038840.png

 

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.

Avatar

Correct answer by
Community Advisor

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()