Get child pages using node depth using Querybuilder | Community
Skip to main content
supriya-hande
Level 4
November 20, 2023
Solved

Get child pages using node depth using Querybuilder

  • November 20, 2023
  • 3 replies
  • 2591 views

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?

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

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.value=Triangle

 
 
here is the example of core component

3 replies

partyush
Community Advisor
Community Advisor
November 20, 2023

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.

supriya-hande
Level 4
November 20, 2023

@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/wcm/core/components/internal/models/v1/ListImpl.java#L351

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

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
November 20, 2023

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.value=Triangle

 
 
here is the example of core component
Arun Patidar
kautuk_sahni
Community Manager
Community Manager
November 23, 2023

@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