Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

AEM TAGS

Avatar

Level 4

Hi @All,

I have a requirement that i need to have tag title from /etc/tags/... i am using 

Tag tag = resourceResolver.adaptTo(Tag.class);
String localeTitleTags = tag.getTitle(pageLocale);

but String localeTitleTags = tag.getTitle(pageLocale); 

is returning NULL

Locale pageLocale = currentPage.getLanguage(false);

For Locale 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @lone_Ranger ,

 

Please refer this documentation for tagging api.

 

https://experienceleague.adobe.com/docs/experience-manager-64/developing/platform/tagging/building.h...

 

Please check if the below code helps

 

TagManager tagManager = resourceResolver.adaptTo(TagManager.class);
Locale pageLocale = currentPage.getLanguage(false);
Tag[] tags = tagManager.getTags(resource);	
for(Tag tag: tags) {
	//fetch tag title
}

and also check in tag console if you have respective tags for each locale, else it will fallback to default. For e.g like below

 

kishorekumar14_0-1630215693505.png

 

View solution in original post

4 Replies

Avatar

Level 9

the code you are using is correct. couple of things to check

 

1. are you getting pageLocale correctly

2. if for corresponding locale tags are configured if not then at least default system locale tag is setup

 

above will return not if one of them doesn't match. so i suggest to cross check.

 

 

Avatar

Community Advisor

Hi,

 

In your code, where are you passing the property for which title need to be read ? Seems you did not share it.  see below code for reference

TagManager tagMgr = resource.getResourceResolver().adaptTo(TagManager.class); log.debug("Loading tags from {}@{}", resource.getPath(), property); List<String> tags = new ArrayList<String>(); String[] values = resource.getValueMap().get(property, String[].class); if (values != null) {  for (String value : values) {   tags.add(tagMgr.resolve(value).getTitle());  } }  

 

Avatar

Correct answer by
Community Advisor

Hi @lone_Ranger ,

 

Please refer this documentation for tagging api.

 

https://experienceleague.adobe.com/docs/experience-manager-64/developing/platform/tagging/building.h...

 

Please check if the below code helps

 

TagManager tagManager = resourceResolver.adaptTo(TagManager.class);
Locale pageLocale = currentPage.getLanguage(false);
Tag[] tags = tagManager.getTags(resource);	
for(Tag tag: tags) {
	//fetch tag title
}

and also check in tag console if you have respective tags for each locale, else it will fallback to default. For e.g like below

 

kishorekumar14_0-1630215693505.png

 

Avatar

Community Advisor

Hi @lone_Ranger,

Per the snippet shared, issue is not with Locale. tag.getTitle("locale") will return default title(as if we are invoking getTitle()) if locale is null. 

Things to cross check

  • Check if your resourceResolver is having permissions to access /etc/tags
  • You are directly adapting resourceResolver to Tag object. Instead it should be to TagManager
    • If you want to adapt to a Tag object, it should be resource object that can be adapted to Tag, say resource.adaptTo(Tag.class)
  • The resource which are trying to get as Tag object should be a resource of type cq:Tag (or resolvable as Tag resource)

Please share the content structure sample screenshot which you are trying to resolve as Tag (and hence get its localized Title) and place where you have this snippet (Is it on Sling Model or on Servlet)