Hi,
Do we have any way to find empty page list in aem content by using query builder or groovy script.How can we find list of pages if it has only pagetitle component ?. I have tried with below link it's giving list of pages which has page title and other components as well but the list is very big since we have page title component in many of pages. I need the page list which has only pagetitle component and it should not any other componnet in page.
https://gist.github.com/ahmed-musallam/780d92ee1ea30c7101054506364d6a25
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @vijitha
you can use a Groovy script with the AEM QueryBuilder API. Below is an example script that performs a similar operation:
def queryBuilder = sling.getService(QueryBuilder)
def query = queryBuilder.createQuery(PredicateGroup.create([
// Add conditions to match your template
queryBuilder.path("/content/your-site"),
queryBuilder.template("/apps/your-site/templates/your-template"),
// Exclude pages with other components
queryBuilder.and(
queryBuilder.exists("jcr:content/your-component", "true"),
queryBuilder.not().exists("jcr:content/*")
)
]), sling.getRequest())
def searchResults = query.getResult().getHits()
searchResults.each { hit ->
def pagePath = hit.getPath()
println("Page Path: $pagePath")
}
________________________________________
Using Query Builder
ex: type=cq:Page
path=/content/your-site
property=jcr:content/cq:template
property.value=/apps/your-site/templates/your-template
property.operation=like
property.1_property=jcr:content/your-component
property.1_property.operation=exists
property.2_property=jcr:content
property.2_property.operation=not
property.3_property=jcr:content/*
property.3_property.operation=exists
Thanks.
Hi @vijitha
you can use a Groovy script with the AEM QueryBuilder API. Below is an example script that performs a similar operation:
def queryBuilder = sling.getService(QueryBuilder)
def query = queryBuilder.createQuery(PredicateGroup.create([
// Add conditions to match your template
queryBuilder.path("/content/your-site"),
queryBuilder.template("/apps/your-site/templates/your-template"),
// Exclude pages with other components
queryBuilder.and(
queryBuilder.exists("jcr:content/your-component", "true"),
queryBuilder.not().exists("jcr:content/*")
)
]), sling.getRequest())
def searchResults = query.getResult().getHits()
searchResults.each { hit ->
def pagePath = hit.getPath()
println("Page Path: $pagePath")
}
________________________________________
Using Query Builder
ex: type=cq:Page
path=/content/your-site
property=jcr:content/cq:template
property.value=/apps/your-site/templates/your-template
property.operation=like
property.1_property=jcr:content/your-component
property.1_property.operation=exists
property.2_property=jcr:content
property.2_property.operation=not
property.3_property=jcr:content/*
property.3_property.operation=exists
Thanks.
Hi @Raja_Reddy
Thanks for your reply. I have tried with above query in my local it's giving the list of pages which has pagetitle componenet and also other component. I need the page list where the page is having only page title component.
Can you suggest how to get the empty page list in aem ?
Hi @vijitha
check this query
type=nt:unstructured
path=/content/countries
property=sling:resourceType
property.value=xxx/components/xxx/xxx
property.operation=like
p.limit=-1
Hi @Raja_Reddy
Thanks for your suggestion. I have tried with above query it's also giving the page list(where we have page title component and other componenet also) but I need to get the list of either empty pages or the page which has only pagetitle component in it (EX:Page should have only page title component if incase page has other component along with title component it should come in results)
Hi @vijitha,
In Adobe Experience Manager (AEM), you can use Query Builder to find pages with specific criteria, such as those containing only the pagetitle component. However, directly querying for pages based on the existence of a single component might not be feasible, as Query Builder primarily searches for properties and nodes, not individual components.
You can try it with groovy scripts
import com.day.cq.wcm.api.Page
import com.day.cq.wcm.api.PageManager
// Obtain the PageManager
PageManager pageManager = resourceResolver.adaptTo(PageManager.class)
// Function to check if a page contains only the pagetitle component
def hasOnlyPageTitleComponent(Page page) {
def jcrContent = page.getContentResource("jcr:content")
if (jcrContent != null) {
def components = jcrContent.getChildren().collect { it.getName() }
return components.size() == 1 && components.contains("pagetitle")
}
return false
}
// Traverse the content structure to find pages with only pagetitle component
def findPagesWithOnlyPageTitleComponent(Page page) {
if (hasOnlyPageTitleComponent(page)) {
log.info("Page Path: " + page.getPath())
} else {
page.listChildren().each { childPage ->
findPagesWithOnlyPageTitleComponent(childPage)
}
}
}
// Start traversal from the root path
def rootPath = "/content"
def rootPage = pageManager.getPage(rootPath)
if (rootPage != null) {
findPagesWithOnlyPageTitleComponent(rootPage)
} else {
log.error("Root page not found")
}
Thanks for your suggestion. I am new to Groovy script, Is above script will give the page list where we have only page title component or it the list of page where we have pagetitle and other componets as well and when I tried to execute above script it's giving only execuation time and I don't see ant println in it. Please correct me if I am not correct.
Basically I need empty pagelist for over all site or if page has only title component and it should not contain any other component.
@vijitha 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.
Views
Replies
Total Likes