Expand my Community achievements bar.

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 Reply

Avatar

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