Reputation: 11
I am using AEM 6.1 and need to populate a list of filters dynamically based on the list of tags that are available. The tags are nested so that there is a region tag, then country tags nested inside of it, and then city tags nested inside their countries. I need to retrieve the region and all of its children, I've attempted to use an ajax call to return them but it only seems to return me the top level node and none of the children. There doesn't seem to be much information regarding the JS Use API's interaction with the Tag Manager. Really thankful for any information or links that can point me in the right direction.
Upvotes: 1
Views: 2788
Reputation: 750
Why do you really need to use JS use API? The JS use API's are on server side not client side even though they are Javascript.
I guess you might be comfortable in doing it via Java use API. you just have to get the path to tag and adapt it to Tag. Check a sample below.
Resource tagResource = getResourceResolver().getResource(tagPath);
if (tagResource != null) {
final Iterable<Resource> children = tagResource.getChildren();
final Iterator<Resource> itr = children.iterator();
while (itr.hasNext()) {
final Resource item = itr.next();
final Tag tag = item.adaptTo(Tag.class);
if (tag != null) {
//Put in map or list to be returned to sightly html.
}
}
}
BTW you can write Java code inside JS use API. Check Blog
Upvotes: 0
Reputation: 1856
TagManager
class implicit object is not available in Sightly Global objects list
You would need to get the instance of TagManager
using adaptTo
and other global available objects
var resourceResolver = resource.getResourceResolver();
var tagManager = resourceResolver.adaptTo(Packages.com.day.cq.tagging.TagManager);
Upvotes: 1