Skip to main content

Filter

Remove CQ Decoration Tags

The following Sling filter removes all AEM added html component deocration tags

CqDecorationFilter.java
/**
* Remove aem component wrapper div on publish
* https://github.com/Adobe-Consulting-Services/acs-aem-samples/blob/master/core/src/main/java/com/adobe/acs/samples/filters/impl/SampleSlingIncludeFilter.java
*/

@Component
@SlingServletFilter(
scope = {SlingServletFilterScope.INCLUDE},
pattern = "/content/experience-fragments/.*",
extensions = {"html"},
methods = {"GET"}
)
public class CqDecorationFilter implements Filter {

@Override
public void init(FilterConfig filterConfig) throws ServletException {
// do nothing
}

@Override
public final void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
ServletException {

final WCMMode mode = WCMMode.fromRequest(request);
final IncludeOptions includeOptions = IncludeOptions.getOptions(request, true);

// Only execute in Publish mode
if (WCMMode.DISABLED.equals(mode)) {
log.debug("Removing component wrapping div.");
// Disable CQ Decoration on cq:includes or sling:includes, only in Publish mode
includeOptions.setDecorationTagName("");
}

chain.doFilter(request, response);
}

@Override
public void destroy() {
// do nothing
}
}