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
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @lone_Ranger ,
Please refer this documentation for tagging api.
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
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.
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()); } }
Hi @lone_Ranger ,
Please refer this documentation for tagging api.
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
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
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)
Views
Like
Replies