Retrieve targeted components | Community
Skip to main content
Level 6
October 24, 2024
Solved

Retrieve targeted components

  • October 24, 2024
  • 1 reply
  • 444 views

 

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?

Best answer by Dipti_Chauhan

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

 

1 reply

Dipti_Chauhan
Community Advisor
Dipti_ChauhanCommunity AdvisorAccepted solution
Community Advisor
October 28, 2024

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