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

Create a target component programmatically

Avatar

Former Community Member

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

1 Accepted Solution

Avatar

Correct answer by
Level 10

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.

View solution in original post

4 Replies

Avatar

Employee

Hi Abdoulaye,

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

Regards,

Opkar

Avatar

Former Community Member
        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

Avatar

Former Community Member

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

Avatar

Correct answer by
Level 10

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.