Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Current Page component

Avatar

Level 4

How i can fetch current page components in cq5?

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi,

Have you tried to use the TagManager API [1]? It has some search methods, which return resources; these can return any resource with the given tags; then you need to post-process the result and find the pages for these resources (if these exist); if you can limit your requirement only to find pages which have a certain tag, you can try to use the adaptTo() approach to convert your search result resources to pages (if applicable).

Resource r = ... Page page = r.adaptTo(Page.class); if (p != null) { // read title and path to create the link } else { // the tag is not on page, but rather on a different node }

HTH,

Jörg

[1] https://docs.adobe.com/docs/de/aem/6-0/develop/ref/javadoc/com/day/cq/tagging/TagManager.html

View solution in original post

3 Replies

Avatar

Employee Advisor

Hi,

so you are intereested in the page component? 

String pageResourceType = currentPage.getProperties().get("jcr:resourceType");

You can only get the resourcetype reliably, page.getTemplate() doesn't work on publish

Jörg

Avatar

Level 4

Jörg Hoh wrote...

Hi,

so you are intereested in the page component? 

  1. String pageResourceType = currentPage.getProperties().get("jcr:resourceType");

You can only get the resourcetype reliably, page.getTemplate() doesn't work on publish

Jörg

 

Thanks for the reply.

My requirement is : i will search a page based on tag, it will show list of page having the tag name.

In result it will show page title,and link .

My need is : i need to show the list of component under the corresponding page.

 

Ex : Am searching "orientation" tag based search.

in result it will show pages, that contains orientation tag.

at that time i need to fetch corresponding result page components.

Avatar

Correct answer by
Employee Advisor

Hi,

Have you tried to use the TagManager API [1]? It has some search methods, which return resources; these can return any resource with the given tags; then you need to post-process the result and find the pages for these resources (if these exist); if you can limit your requirement only to find pages which have a certain tag, you can try to use the adaptTo() approach to convert your search result resources to pages (if applicable).

Resource r = ... Page page = r.adaptTo(Page.class); if (p != null) { // read title and path to create the link } else { // the tag is not on page, but rather on a different node }

HTH,

Jörg

[1] https://docs.adobe.com/docs/de/aem/6-0/develop/ref/javadoc/com/day/cq/tagging/TagManager.html