Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Read cq:tags associated with current page

Avatar

Level 3

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @sateeshreddy 

 

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

View solution in original post

4 Replies

Avatar

Community Advisor

Hello @sateeshreddy 

 

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...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

Avatar

Correct answer by
Community Advisor

Hi @sateeshreddy 

 

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

Avatar

Level 3

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

Avatar

Community Advisor

Hi @sateeshreddy 

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