Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list
SOLVED

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

Avatar

Not applicable

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.

1 Accepted Solution

Avatar

Correct answer by
Employee

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

Avatar

Not applicable

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...

Avatar

Correct answer by
Employee

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)

Avatar

Not applicable

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?

Avatar

Level 2

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

Avatar

Level 2

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