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
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

AEM TAGS

saurabh_kumar_02
Level 2
Level 2

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
kishorekumar14
Correct answer by
Level 7
Level 7

Hi @saurabh_kumar_02 ,

 

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
rush_pawan
Community Advisor
Community Advisor

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

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

 

kishorekumar14
Correct answer by
Level 7
Level 7

Hi @saurabh_kumar_02 ,

 

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

Vijayalakshmi_S
Community Advisor
Community Advisor

Hi @saurabh_kumar_02,

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)