Getting Tag title from javascript | Community
Skip to main content
JoseBerciano
Level 3
July 22, 2016

Getting Tag title from javascript

  • July 22, 2016
  • 3 replies
  • 7260 views

Hi all,

From one javascript file I am receiving the following array:

tags ["parenttag:tag1/subtag1", "parenttag:tag1/subtag2", "parenttag:tag1/subtag3", "parenttag:tag2/subtag4", "parenttag:tag2/subtag5"]

I would need to get each tag title from these values. E.g from "parenttag:tag1/subtag1" the tag title is defined as "Subtag 1"

Is there any way of doing this from javascript?

 

Thank you.

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

3 replies

kautuk_sahni
Community Manager
Community Manager
July 22, 2016

Hi 

Let say:

Var a = ["parenttag:tag1/subtag1", "parenttag:tag1/subtag2", "parenttag:tag1/subtag3", "parenttag:tag2/subtag4", "parenttag:tag2/subtag5"];

So ,

a[0] would print :-  "parenttag:tag1/subtag1"

a.length := 5

and 

Var result = a[0].split("/");

result would be  :- ["parenttag:tag1", "subtag1"]

and  result[1] would give you:-  "subtag1"

 

Now repeat this in a for loop from 1 to a.length

I hope this would help you.

Thanks and Regards

Kautuk Sahni

Kautuk Sahni
JoseBerciano
Level 3
July 22, 2016

Hi kautuksahni,

thanks for you help but I am afraid that does not work for me, as I could have "parenttag:tag1/subtag1" which its actual title could be "Little Kitties"

Is any CQ object I can call from the front end to get this value? or any other way/workaround to do so?

edubey
Level 10
July 24, 2016

AFAIK, there is no OOTB direct way to resolve the tag and get the title in JS

But you might want to look into the code of tagpicker field in TOUCH UI and one option can be a servlet where you can pass Id's in one go and get all title

Thanks

smacdonald2008
Level 10
July 22, 2016

Trying to read the DOM to get tags information is not best practice. 

There are much better ways to get Tag in AEM via the Tag Manager API. See these articles: 

Developing a Sightly Component that searches for AEM Content Tags

Using Custom Tag Libraries to search for AEM Content Tag

Hope these help

rajkumarsamala
Level 2
September 15, 2017

you can do like this, it's very simple,

$.ajax({

          type: "GET",

          url: "/etc/tags/TestTag/"+Tagid+".json", //

          success : function(data) {

               TagTitle= data["jcr:title"];

          }

});

edubey
Level 10
September 15, 2017

No, I don't think it's simple.

1. Direct URL could be blocked via dispatcher.

2. By default, Anonymous user does not have tags permission. https://docs.adobe.com/docs/en/aem/6-2/administer/content/tags.html#Setting Tag Permissions

Thanks