以编程方式将 HTML 代码添加到 AEM 组件中

Add HTML code into AEM component programmatically

我需要在添加到页面的每个 AEM 组件上添加 html 评论。任何人都知道如何做到这一点?

我想做这样的事情:

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

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

您需要使用 cq:listeners。这用于捕获组件生命周期中的各种事件。有一个侦听器 afterinsert 在页面上插入组件时触发。为此事件创建一个处理程序脚本,您可以使用它向 DOM 添加注释(例如,在组件 div 之前)。 Jquery 可以轻松帮助您,如图 here

并且 afterdelete 侦听器可用于从 DOM 中删除该评论。

有关听众的更多详细信息 here