Expand my Community achievements bar.

Nomination window for the Adobe Community Advisor Program, Class of 2025, is now open!
SOLVED

Retrieve targeted components

Avatar

Level 4

 

Hello, I have a requirement to determine if the page has any targeted components (ContextHub Personalization) in it and retrieve the component details, if any. How can we retrieve the details in a Sling model as I don't want to go with the Servlet approach? Can someone tell me if you have already implemented a similar use case in your project?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi

 You can use Sling query<org.apache.sling.query.SlingQuery> for the same.Targated component's resource type becomes "cq/personalization/components/target" So in your sling model you can chedk if current page have this resource type

e.g

{CURRENT_PAGE_RESOURCE}.children().has("cq/personalization/components/target");   

 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi

 You can use Sling query<org.apache.sling.query.SlingQuery> for the same.Targated component's resource type becomes "cq/personalization/components/target" So in your sling model you can chedk if current page have this resource type

e.g

{CURRENT_PAGE_RESOURCE}.children().has("cq/personalization/components/target");