Expand my Community achievements bar.

SOLVED

Content fragment reference should get publish all the CF which has the same reference

Avatar

Level 2

I have a requirement as below

In One Content fragment , i have added fragment reference (CF A)  and it will refer another fragment.  (CF B)

Suppose if i do any change in CF B, same changes should get publish CF A also which CF B is refered .

Because in CF A , i wrote a servlet to publish the CF A values to third party on publish /save the CF A.

So Reference and idea will be good.

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@YuganSan 

 

Create a class to implement Resource Change Listener onChange()

Reference: https://sling.apache.org/apidocs/sling9/org/apache/sling/api/resource/observation/ResourceChangeList...

 

Use AssetManager.getAsset() to retrieve the CF A and B. 

Reference: https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/adobe/...

 

For publishing CF, you can try using the below:

https://adobe-sites.redoc.ly/#operation/fragments/publish

 

View solution in original post

6 Replies

Avatar

Community Advisor

Hi, 

Apologies, could you please rephrase your question or specify the issue you have for the community? If it's an idea or suggestion for a product enhancement, you can submit it here: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager-ideas/idb-p/adobe-experien... 

Hope this helps.



Esteban Bustamante

Avatar

Community Advisor

Hi @YuganSan 

To achieve the requirement where changes in a referenced Content Fragment (CF B) should trigger updates in the fragment that references it (CF A), you can consider any of the folllowing:

Event Handling: Implement an event listener in AEM that listens for changes in CF B. When CF B is modified, the event listener can trigger a workflow or a custom script to update CF A accordingly.

Sling Model Exporter: Utilize the Sling Model Exporter to export the content of CF B as JSON. CF A can then use this JSON to dynamically include the content from CF B. This way, when CF B is updated and published, CF A will automatically reflect the changes when it’s accessed or published.

Avatar

Community Advisor

Hi @YuganSan ,

To ensure that changes made to Content Fragment B (CF B) are reflected and published in Content Fragment A (CF A), which references CF B, you can follow these steps:

  1. Event Listeners: Implement an event listener in Adobe Experience Manager (AEM) that listens for changes to CF B. When CF B is updated and saved, the event listener triggers a process to update and republish CF A.

  2. Replication Agent or Workflow: Use a replication agent or workflow in AEM to automate the publishing process for CF A when CF B is updated. When CF B is saved, trigger the replication agent or workflow to publish CF A.

  3. Programmatic Approach:

    • Develop a custom servlet or service in AEM that monitors changes to CF B.
    • When CF B is updated, programmatically retrieve all instances of CF A that reference CF B.
    • Update the content of CF A with the changes from CF B.
    • Republish CF A using AEM's publishing APIs.
  4. Custom Workflow Step: Create a custom workflow step in AEM that is triggered when CF B is updated. This workflow step retrieves all instances of CF A that reference CF B and updates their content accordingly. Once updated, the workflow can publish CF A.

  5. Tagging Approach:

    • Tag CF B with a unique identifier or tag.
    • In CF A, include a search query or logic that identifies and retrieves all instances of CF A that reference CF B based on the tag.
    • Whenever CF B is updated and saved, reapply the unique identifier or tag.
    • CF A will automatically reflect the changes made to CF B when it is published due to the dynamic nature of the search query.
  6. Linking Approach:

    • Instead of directly referencing CF B in CF A, maintain a link or reference between CF A and CF B using a custom metadata field or property.
    • When CF B is updated, the linking mechanism triggers an update in CF A to reflect the changes made to CF B.
    • Publish CF A to ensure that the changes are reflected on the published site.

Choose the approach that best fits your requirements and the complexity of your implementation. Consider factors such as scalability, performance, and maintainability when designing the solution. Additionally, test the solution thoroughly to ensure that changes made to CF B are consistently reflected and published in CF A as expected.

Avatar

Level 2

Hi

If i am trying with Event listener, How we can publish the CF A? Could you please send sample to do publish in Event Listener will be helpful

Avatar

Correct answer by
Community Advisor

@YuganSan 

 

Create a class to implement Resource Change Listener onChange()

Reference: https://sling.apache.org/apidocs/sling9/org/apache/sling/api/resource/observation/ResourceChangeList...

 

Use AssetManager.getAsset() to retrieve the CF A and B. 

Reference: https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/adobe/...

 

For publishing CF, you can try using the below:

https://adobe-sites.redoc.ly/#operation/fragments/publish

 

Avatar

Administrator

@YuganSan 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