Create a target component programmatically | Community
Skip to main content
October 16, 2015
Solved

Create a target component programmatically

  • October 16, 2015
  • 4 replies
  • 1776 views

Hi,

I would like to create a target component (sling:resourceType should be cq/personalization/components/target) programmatically.

My scenario is as follows:

- I have a par component_A that has a rendering file component_A.html. This HTML render file calls a JSP file  using the following sightly statement

<sly data-sly-include="componentCreator.jsp" data-sly-unwrap />

- the included "componentCreator.jsp" should then create a target component and pass it to component_A

Does anybody know how to achieve this? Any help would be appreciated.

Regards, Abou

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 Lokesh_Shivalingaiah

add a node with a sling:resourceType 'cq/personalization/components/target' programatically similar to other nodes. This creates a target component

Under this, you can create a node by name 'default' with the sling:resourceType mapping to your component would get the default content to it.

4 replies

Employee
October 16, 2015

Hi Abdoulaye,

what you have provided above is the technical requirements. What are you business requirements for this functionality?

Regards,

Opkar

October 16, 2015
        Thank you bsloki. I know the manual way you describe in your answer. But my question is how to create a target component programmatically using Java Code? Regards
October 16, 2015

Hi Opkar,

the business requirement is to place target components on dynamically generated websites and then later decide via business logic if a special offer should be displayed at the target component or not.

The main reason why i need this functinality is that the websites are generated automatically and contains several <div> elements in which a special offer can be displayed or not according to a current campaign.

Thanks in advance for your help

Lokesh_Shivalingaiah
Lokesh_ShivalingaiahAccepted solution
New Participant
October 16, 2015

add a node with a sling:resourceType 'cq/personalization/components/target' programatically similar to other nodes. This creates a target component

Under this, you can create a node by name 'default' with the sling:resourceType mapping to your component would get the default content to it.