내 커뮤니티 업적 표시줄을 확대합니다.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.

해결됨

Adding dynamic css class on the outer html tag of a component

Avatar

Level 4

Hi everybody,

we have a component and we would like to add a 'dynamic' css class on its outer html tag. When I say dynamic, I mean for example chosen via a dialog. This would be easy in case the tag to add the css class is internal to the template but in our case is the outer one.

Example: the html template of the cq component

<div class="another-tag my-dynamic-class-chosen-via-a-cq-dialog">

component body

</div>

We already tried to override the parsys, but this is a real pain another solution I have thought about is writing a sling component filter.

Do you have any other idea?

Thank you!

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Level 4

For the ones who could be stuck on this issue I solved it by implemeting a SlingFilter with COMPONENT scope as described here:

http://stackoverflow.com/questions/26102239/aem-cq-conditional-css-class-on-decoration-tag

One thing to be aware of is to correctly rank our Decorator filter in the order list. It should come after 

com.day.cq.wcm.core.impl.WCMComponentFilter

otherwise the custom class id added in the wrong place.

Correct rank order is -100 in AEM 6 SP2.

원본 게시물의 솔루션 보기

4 답변 개

Avatar

Level 4
Hi and thank you for your response. I was already aware of cq:htmlTag but this does not accomplish our needs. I try to explain better: the class I want to add comes from a dialog input so is not static but it's dynamic according to user input. Again I want to add the class to the outer div so I am not in control of the html generated div but still cq:htmlTag won't solve this issue.

Avatar

Employee

Avatar

정확한 답변 작성자:
Level 4

For the ones who could be stuck on this issue I solved it by implemeting a SlingFilter with COMPONENT scope as described here:

http://stackoverflow.com/questions/26102239/aem-cq-conditional-css-class-on-decoration-tag

One thing to be aware of is to correctly rank our Decorator filter in the order list. It should come after 

com.day.cq.wcm.core.impl.WCMComponentFilter

otherwise the custom class id added in the wrong place.

Correct rank order is -100 in AEM 6 SP2.

Avatar

Employee

You can find out in your filter if the component is included as part of the page by checking javax.servlet.include.servlet_path in request attribute. If request.getAttribute("javax.servlet.include.servlet_path") is not null then, you got your compoennt. Adapt the resource, get the property and you can decorate the way you want.