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
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
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.
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.
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:
Resource resource = resourceResolver.getResource(imagePath); Asset asset = resource.adaptTo(Asset.class);
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.
Views
Likes
Replies