April 27, 2020
Estimated Post Reading Time ~

How to retrieve the pages created with particular template using Query Builder API

This post will explain how to retrieve the pages created with particular template using Query Builder API in Adobe Experience Manager(AEM)/Adobe CQ5

API Reference:

@Reference
QueryBuilder queryBuilder;

Session session = repository.loginAdministrative(null);

String resourcePath="/content/sample/site-demo/en";

Map<String, String> searchMap = new HashMap<String, String>();
searchMap.put("type", "cq:Page");
searchMap.put("path", resourcePath);
searchMap.put("property", "jcr:content/cq:template");
searchMap.put("property.value", "/apps/common/templates/sampleview");
searchMap.put("p.limit", "-1");

Query query = queryBuilder.createQuery(PredicateGroup.create(searchMap),session);

SearchResult result = query.getResult();
for(Hit hit:result.getHits()) {

String pagePath = hit.getPath();
Node pageNode = hit.getNode
}


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.