Expand my Community achievements bar.

SOLVED

Get child pages using node depth using Querybuilder

Avatar

Level 4

There is a requirement where we want to fetch child pages of parent page based on Node depth. Its default implementation in Core v3 list component but we want this feature in one custom component. We have written below query in querybuilder debugger tool to get child pages by node depth.

path=/content/hostplus-program/home/about-us
property=jcr:content/cq:template
property.value=/conf/hostplus-program/settings/wcm/templates/article
property.depth=1
p.limit=-1

but we are getting all child pages. I found one reference where its working with jcr:title property:
path=/content/hostplus-program/home/about-us
property=jcr:title
property.value=News
p.nodedepth=1
p.hits=full

but not working as expected if we use any other jcr or cq property. Is there any way to achieve this?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @supriya-hande 
You can't filter the child pages based on the query if you areusing nodedepth.

 

nodedepth is used to include child nodes in the QueryBuilder response. To do this, you must specify

p.nodedepth=n
 

Where n is the number of levels that you want the query to return. For a child node to be returned, it must be specified by the properties selector

p.hits=full
 

Example:

http://localhost:4502/bin/querybuilder.json?p.hits=full&p.nodedepth=5&property=jcr%3atitle&property....

 
 
here is the example of core component


Arun Patidar

View solution in original post

4 Replies

Avatar

Community Advisor

Hi @supriya-hande 

 

If you want to filter child pages based on node depth and a specific property, and you're facing issues with property.depth, you can achieve this by combining the conditions using group.p.and and p.nodedepth. Here's an example:

 

 

path=/content/hostplus-program/home/about-us
group.p.and=true
group.1_property=jcr:content/cq:template
group.1_property.value=/conf/hostplus-program/settings/wcm/templates/article
group.1_property.operation=equals
p.nodedepth=2
p.limit=-1

 

In this example, group.p.and=true ensures that all conditions inside the group must be satisfied. The p.nodedepth=2 ensures that you get only child pages (depth 2) of the specified path.

Adjust the jcr:content/cq:template property value and any other conditions as needed. This should help you filter child pages based on both the template and node depth.

Avatar

Level 4

@partyush I tried above one but still I am getting same results if I provide p.nodedepth=1 or p.nodedepth=2 Ideally this should retrieve pages only from specified child node depth. I checked implementation of Core list component here for node depth: 
https://github.com/adobe/aem-core-wcm-components/blob/main/bundles/core/src/main/java/com/adobe/cq/w...

There is collectChildren(int depth, @NotNull final Page parent) function which is recursive call to collect children pages.

Avatar

Correct answer by
Community Advisor

Hi @supriya-hande 
You can't filter the child pages based on the query if you areusing nodedepth.

 

nodedepth is used to include child nodes in the QueryBuilder response. To do this, you must specify

p.nodedepth=n
 

Where n is the number of levels that you want the query to return. For a child node to be returned, it must be specified by the properties selector

p.hits=full
 

Example:

http://localhost:4502/bin/querybuilder.json?p.hits=full&p.nodedepth=5&property=jcr%3atitle&property....

 
 
here is the example of core component


Arun Patidar

Avatar

Administrator

@supriya-hande Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni