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

Tagmanager api find tags

Avatar

Level 2

Hi, a custom component which build by extending the image component in which added text and description, so when using that component in page then how to print the metadata suppose cq:tags associated with that custom component image which authored

Topics

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

 

The correct way to achieve this is by placing all the data you wish to expose in the HTML within a Sling model. The Sling model can retrieve any metadata associated with the resource and execute custom processes to obtain and expose additional information to your component. You can learn more about Sling models here: https://dev.to/avi413/dynamic-navigation-in-aem-using-sling-models-and-htl-2794 

 

If your component is inheriting from a different component, you can use the delegate pattern in sling models to extend the original functionality and include your custom logic, learn more here: https://medium.com/@manumathew28.94/aem-delegation-pattern-for-sling-models-30d8447b74bc 

 

For the specific usage of "cq:tags", you can see here an example of how to get and expose them: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/read-cq-tags-associated-wi... 

 

Hope this helps.

 



Esteban Bustamante

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi,

 

The correct way to achieve this is by placing all the data you wish to expose in the HTML within a Sling model. The Sling model can retrieve any metadata associated with the resource and execute custom processes to obtain and expose additional information to your component. You can learn more about Sling models here: https://dev.to/avi413/dynamic-navigation-in-aem-using-sling-models-and-htl-2794 

 

If your component is inheriting from a different component, you can use the delegate pattern in sling models to extend the original functionality and include your custom logic, learn more here: https://medium.com/@manumathew28.94/aem-delegation-pattern-for-sling-models-30d8447b74bc 

 

For the specific usage of "cq:tags", you can see here an example of how to get and expose them: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/read-cq-tags-associated-wi... 

 

Hope this helps.

 



Esteban Bustamante

Avatar

Level 5

Hi @knki 
@EstebanBustamante solution above is apt.
While in context to sling model, you can access and print the metadata of a custom component, such as cq:tags, by using the Sling API. Here’s a general approach:

  1. First, you need to get the resource associated with the image. You can do this by adapting the current resource to a Node or Asset:
Resource resource = resourceResolver.getResource(imagePath);
Asset asset = resource.adaptTo(Asset.class);
  1. Once you have the Asset, you can access its metadata:
ValueMap properties = asset.adaptTo(ValueMap.class);
String[] tags = properties.get("cq:tags", String[].class);

 

Also, note that you need sufficient permissions to read the metadata. If you encounter any permission issues, please check your user’s permissions.