Read cq:tags associated with current page | Community
Skip to main content
Level 3
July 4, 2023
Solved

Read cq:tags associated with current page

  • July 4, 2023
  • 2 replies
  • 2344 views

Hello All,

I am trying to read the cq:tags - multivalued property into my sling model . However, when I read it is only returning single value not multi values.

 

Sample code :

 

valueMap.get("cq:tags",String[].class);

or 

currentNode.getProperty("cq:tags").values();

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 Nupur_Jain

Hi @sateeshkreddy 

 

Could you please give us more context like:

1. Is sling model being called on page component or content component?

you can also directly use annotation @Inject or @ValueMap to get values like:

@Inject ()
@Named("cq:tags")

String[] cqTags;

OR

@ValueMapValue(name="cq:tags")
String[] cqTags;


2. Please provide screenshot of crx/de of node where cq:tags property is saved. Ideally the methods you used should have worked.

3. Also, currentNode.getProperty("cq:tags").values(); So, Here, we need to call getValues() to get Value Array instead of values().

Hope this helps!

Thanks,
Nupur

2 replies

aanchal-sikka
Community Advisor
Community Advisor
July 4, 2023

Hello @sateeshkreddy 

 

Can you please try using the getTags() from tagManager API?

https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/index.html?com/day/cq/tagging/TagManager.html

 

 

Tag[] pageTags = tagManager.getTags(pageContentresource); if (pageTags != null && pageTags.length > 0) { tags = new String[pageTags.length]; for (int i = 0; i < pageTags.length; i++) { tags[i] = pageTags[i].getTitle(); } } else { tags = ArrayUtils.EMPTY_STRING_ARRAY; }

 

Aanchal Sikka
Nupur_Jain
Adobe Employee
Nupur_JainAdobe EmployeeAccepted solution
Adobe Employee
July 4, 2023

Hi @sateeshkreddy 

 

Could you please give us more context like:

1. Is sling model being called on page component or content component?

you can also directly use annotation @Inject or @ValueMap to get values like:

@Inject ()
@Named("cq:tags")

String[] cqTags;

OR

@ValueMapValue(name="cq:tags")
String[] cqTags;


2. Please provide screenshot of crx/de of node where cq:tags property is saved. Ideally the methods you used should have worked.

3. Also, currentNode.getProperty("cq:tags").values(); So, Here, we need to call getValues() to get Value Array instead of values().

Hope this helps!

Thanks,
Nupur

Level 3
July 4, 2023

It is used in a  component and the model is adapted to SlingHTTPRequest.class.

Nupur_Jain
Adobe Employee
Adobe Employee
July 4, 2023

Hi @sateeshkreddy 

I am assuming you want to get cq:tags property values of page in component. If that is so, 

1. First get Page object of currentPage like 

@ScriptVariable
    private Page currentPage;

2. Then you can get page tags like  

Tag[] tags = currentPage.getTags();

OR

currentPage.getProperties ().get("cq:tags", String[].class);

If cq:tags property is part of component properties itself, then follow the @ValueMapValue annotation as mentioned in my previous reply.


Hope it helps!

Thanks,

Nupur