I have some example code (from Tomek Rękawek on Stack Overflow), adding a class name to the component containing element. This works perfectly, however after installing Service Pack 2 for AEM 6.0 this doesn't work/works differently.
@SlingFilter( scope = SlingFilterScope.COMPONENT, order = -300) public class IncludeOptionsFilter implements javax.servlet.Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { boolean addClass = false; if (request instanceof SlingHttpServletRequest) { final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; final Resource resource = slingRequest.getResource(); final String resourceType = resource.getResourceType(); final String resourcePath = resource.getPath(); // put any custom logic here, eg.: addClass = "foundation/components/carousel".equals(resourceType) && resourcePath.startsWith("/content/geometrixx/en"); } if (addClass) { final IncludeOptions options = IncludeOptions.getOptions(request, true); options.getCssClassNames().add("my-class"); } chain.doFilter(request, response); } }
Before SP2 - Works
Line 205 : <div class="parbase my-class carousel list"><div class="cq-dd-pages">
After SP2 - Doesn't work
The class has now been added to a different component:
Line 299 : <div class="my-class lead"><h2>World Leader in Applied Geometry </h2>