jordiPons
jordiPons

Reputation: 174

Add HTML code into AEM component programmatically

I need to add a html comment on every AEM component that I add to a page. Anyone knows how can this be done?

I want to do something like this:

<!-- comment added -->
< html component>

</ html component>
<!-- comment added -->

Upvotes: 2

Views: 3256

Answers (1)

Abhishek
Abhishek

Reputation: 1190

You need to use cq:listeners. This is used to capture various events in the lifecycle of a component. There is a listener afterinsert which is fired on inserting a component on a page. Create a handler script for this event which you can use to add comments into the DOM (e.g. before the component div). Jquery can easily help you with this as shown here.

And afterdelete listener can be used to remove that comment from the DOM.

More details on listeners here.

Upvotes: 2

Related Questions