AEM · AEM 6 · Sightly

AEM | Remove wrapper HTML Tags in preview mode

AEM is a page based CMS and each page is fabricated with a set of components. AEM use paragraph system to allow editors to drag/drop components on page, and add some wrapper tags around component to identify component in edit mode and allow edit capability. These additional html tags are needed in Edit/Design mode but should be removed in preview mode so that:

  1. Live site do not have unwanted html tags.
  2. Smooth CSS/html integration as frontend team do not consider these unwanted tags while writing html.
  3. Reduce HTML response size & DOM processing (by reducing number of html tags/lines)

To remove these additional html tags, Use one of these solution:

  1. If Component is Author configurable
    If your component allow authors to select configuration in dialog, then you need to use one of following solution, based on template you are using for your component:

    • JSP Template
      For JSP template, add following code snippet in your global.jsp file (If you are using /libs/foundation/global.jsp, then create another global.jsp file in your apps folder, include foundation’s global.jsp and add following lines also) to explicitly remove Decoration Tags

          <c:when test="${ requestScope['']=='EDIT' || requestScope['']=='DESIGN'}">
              <c:if test="${componentContext!=null}">
                  <% componentContext.setDefaultDecorationTagName("div"); %>
              <c:if test="${componentContext!=null}">
                  <% componentContext.setDefaultDecorationTagName(""); %>
    • Sightly Template
      Sightly template allows two ways to avoid decoration tags in preview mode:

      1. use data-sly-unwrap tag to remove the host element from the generated markup while retaining its content. Syntax:
            data-sly-resource="${'par' @resourceType='foundation/components/parsys'}"
            data-sly-unwrap="${!wcmmode.edit && !}"></article>

        In above syntax, we are removing (unrapping) wrapper tag for wcmmode other then edit/design. If your component do not have any design mode configuration, then use following syntax:

            data-sly-resource="${'par' @resourceType='foundation/components/parsys'}"
      2. use <sly /> tag (available from AEM 6.1) to remove AEM generated wrapper elements in preview mode. <sly /> tag do not need additional property and is a better way in comparison to approach#1. Syntax:
        <sly data-sly-resource="${'par' @resourceType='foundation/components/parsys'}"></sly>
  2. If Component is not Author configurable (eg. Breadcrumb, Related data, Search Teasers …)
    If a component do not need any author specific configuration changes, then its a good practice to add cq:noDecoration property in component’s node. If cq:noDecoration is set to true, the component is not rendered with automatically generated div and css classes. Below example shows how we can add cq:noDecoration to our (Breadcrumb) component:

    <?xml version="1.0" encoding="UTF-8"?>
    <jcr:root xmlns:cq="" xmlns:jcr=""

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s