How to read the tags title form cq:tags property? | Community
Skip to main content
Oct 16, 2015 2:27 AM UTC
Solved

How to read the tags title form cq:tags property?

Hi All,

I need to to display tag title on the jsp page. But, I have read tagID from cq:tags property. My question is " How to read Tag title by using tag ID". Please provide code snippet. That would be helpful.

I have followed this code. Please resolve it.

<%String[] tags = campaignProperties.get("cq:tags", new String[0]);
for(String tag : tags){ %>
<% String tagNameSpace = tag; 
ResourceResolver resolver = slingRequest.getResourceResolver();
Resource nameSpaceResource = resolver.getResource(tagNameSpace);
Tag tagTitle = nameSpaceResource.adaptTo(Tag.class);
String tagStr = tagTitle.getTitle(); %>

<h5><%= tagStr.getTitle()%></h5>

Thanks in advance.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Feike_Visser1
Feike_Visser1Accepted solution
Employee
Oct 16, 2015 2:27 AM UTC

You can resolve a Tag via the TagManager (https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/cq/tagging/TagManager.html)

You can do resourceResolver.adaptTo(TagManager.class)

6 replies

namitkochar
Level 2
May 2, 2018 1:03 PM UTC

Can we read tag title and tag name from a tag selected in dialog directly in sightly?

Translate
Oct 16, 2015 2:27 AM UTC

Hi All,

I resolved it with little bit code changes. Please refer it.

<%String[] tagsNameSpace = pathProperties.get("cq:tags", new String[0]);

 for(String tagValue : tagsNameSpace){ %>

       <%  String tagID = tagValue; 

            TagManager tagManager = resourceResolver.adaptTo(TagManager.class);

            Tag tag = tagManager.resolve(tagID);    %>

                    <h5><i><%= tag.getTitle()%> </i></h5><br/>

            <% } %>

 

Thank you all...

Translate
Feike_Visser1
Feike_Visser1Accepted solution
Employee
Oct 16, 2015 2:27 AM UTC

You can resolve a Tag via the TagManager (https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/cq/tagging/TagManager.html)

You can do resourceResolver.adaptTo(TagManager.class)

Translate
Oct 16, 2015 2:27 AM UTC

Hi Feike Visser,

I have resolved it. Right now I need another requirement. After modified code I got all tag titles. But I need that tag titles for each category. Suppose, I read tags titles for Alerts,Audits,DashBoards. So how to separate those tags for related category?

Translate
Tim_Donovanuk
Level 2
Oct 16, 2015 2:27 AM UTC

Are you talking about tag namespaces? These appear as namespace:tagname (e.g. fruit:apple). Both TagManager and Tag has .getNamespace methods.

Translate
Oct 16, 2015 2:27 AM UTC

Yes, Tim Donovan....

Translate