Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

How to display the links of the references where particular page is being referenced.

Avatar

Level 2

Hi Team,

I need to print the link of references in page wherever the current page is being referenced. How should I approach this in optimized way.

 

@arunpatidar  @lukasz-m  @kautuk_sahni 

@SivakumarKanoori @Fanindra_Surat @Jagadeesh_Prakash @krati_garg @iamnjain @somen-sarkar @bajancherry @sunil_kumar_ @shelly-goel @Ganthimathi_R @davidjgonzalezzzz @krishna_garikapati  @Shubham_borole @milind_bachani @krishna_sai @manjunathdj  

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @AditiSi,  

AEM have internal service (ReferenceSearch) to get reference pages. 

ReferenceSearch referenceSearch = new ReferenceSearch();
referenceSearch.setSearchRoot("/content/wrapper");
List<Page> resultSet = referenceSearch.findPageReferencesForResource(
    resolver, CURRENT_PAGE_PATH, -1, -1);

https://developer.adobe.com/experience-manager/reference-materials/cloud-service/javadoc/com/day/cq/... 

 

 

View solution in original post

8 Replies

Avatar

Community Advisor

Your question is not clear to me, but I guess what you are trying to ask is how to share properties between components, if so, there are several approaches you could use, let me detail a couple of them:

 

1. You could use the Shared Component Properties from ACS Commons, you can learn more here: https://adobe-consulting-services.github.io/acs-aem-commons/features/shared-component-properties/ind... https://www.bounteous.com/insights/2016/12/03/shared-component-properties 

2. You could add the shared properties at the page level, that way the properties would be available for every component living on the page

3. You could add a separate and dedicated location to store this shared information, it could be ACS common list, a content fragment, etc

4. You could even embed the image component in the wrap component so you can infer the shared properties in the backend (slind model).

 

Here are more options:
https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/finest-way-to-exchange-dat... 
https://www.alexlockhart.me/2021/01/aem-sharing-data-between-components.html 

 

Hope this helps.



Esteban Bustamante

Avatar

Community Advisor

Hi @AditiSi 

 

Can you please explain your requirement one more time in comments?

Avatar

Correct answer by
Community Advisor

Hi @AditiSi,  

AEM have internal service (ReferenceSearch) to get reference pages. 

ReferenceSearch referenceSearch = new ReferenceSearch();
referenceSearch.setSearchRoot("/content/wrapper");
List<Page> resultSet = referenceSearch.findPageReferencesForResource(
    resolver, CURRENT_PAGE_PATH, -1, -1);

https://developer.adobe.com/experience-manager/reference-materials/cloud-service/javadoc/com/day/cq/... 

 

 

Avatar

Level 2

it's giving error for findPageReferencesForResource method , I'm using aem 6.5 .

 

Avatar

Community Advisor

In AEM v6.5.0, you can use referenceSearch.search(resolver, CURRENT_PAGE_PATH). However, I checked on AEM v6.5.13 and findPageReferencesForResource is available there.

Avatar

Level 2

Hi ,I'm using below code to set the rootpath for reference search but it's not working:
ReferenceSearch referenceSearch = new ReferenceSearch();
referenceSearch.setSearchRoot("/content/test");
Collection<ReferenceSearch.Info> refs = referenceSearch.search(resourceResolver,currentPage.getPath()).values();

 

my currentpage path is something like this -- "/content/test/propertyimages/xyz-bar"
Am I doing something wrong?

Avatar

Community Advisor

Could you please try without specifying the search root path?

Avatar

Level 2

without search root path, it's working but the I want to limit the search path so that it can be efficient and doesn't go through each and every folder. Is there a way to achieve this?