AEM TAGS | Community
Skip to main content
Level 4
August 28, 2021
Solved

AEM TAGS

  • August 28, 2021
  • 4 replies
  • 2157 views

Hi @1905403,

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 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Kishore_Kumar_

Hi @lone_ranger ,

 

Please refer this documentation for tagging api.

 

https://experienceleague.adobe.com/docs/experience-manager-64/developing/platform/tagging/building.html?lang=en

 

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

 

 

4 replies

Pawan-Gupta
Level 8
August 28, 2021

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.

 

 

Ravi_Pampana
Community Advisor
Community Advisor
August 29, 2021

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());  } }  

 

Kishore_Kumar_
Kishore_Kumar_Accepted solution
Level 9
August 29, 2021

Hi @lone_ranger ,

 

Please refer this documentation for tagging api.

 

https://experienceleague.adobe.com/docs/experience-manager-64/developing/platform/tagging/building.html?lang=en

 

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

 

 

Vijayalakshmi_S
Level 10
August 30, 2021

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)