5
votes

How can I remove the decoration tags only in preview/publish mode in AEM sightly?

I have seen the question and answer: AEM/CQ: Conditional CSS class on decoration tag

This removes the decoration but stops me from editing the components because it removes the decoration in edit and design mode as well. What is the condition required so that it will only remove the decoration tags in preview/publish?

I have also seen that it is possible to add the following code into the activate method of my java-use class:

if (!getWcmMode().isEdit() && !getWcmMode().isDesign()) {
           IncludeOptions.getOptions(getRequest(), true).setDecorationTagName("");
    }

This removes all but one of the decoration tags see example below:

HTML in wcmmode=disabled without the above code in the activate method:

<ul class="timeline">
    <div class="section timelineTag">
    <div class="section timelineTag">
    <div class="section timelineTag">
    <li class="clear"></li>
</ul>

HTML in wcmmode=disabled with the above code in the activate method:

<ul class="timeline">
    <div class="section timelineTag">
    <li class="event" href="#">
    <li class="event" href="#">
    <li class="clear"></li>
</ul>

How can I remove the first decoration DIV tag in the ul as it does not disappear when I add the specified code to the activate method?

As requested here is a detailed look at the component in question (updated 07/05/2015):

Java Class

public class TimelineClass extends WCMUse {

    @Override
    public void activate() throws Exception {
        //Remove default wrapping performed by AEM for the preview mode 
        if (!getWcmMode().isEdit() && !getWcmMode().isDesign()) {
               IncludeOptions.getOptions(getRequest(), true).setDecorationTagName("");
        }   
    }
}

HTML code: - There are two components involved in this. First of all the container component that includes the ul tag - Then the tag component which is dragged and dropped from the sidekick into the container to create, in publish, the lists shown above.

Container code:

<div class="az-timeline row">
<section class="small-12 columns">
    <section class="wrapper">
        <ul class="timeline">
            <!-- /* The parsys where all of the timeline tags will be dropped */ -->
            <div data-sly-resource="${'par-wrapper' @ resourceType='foundation/components/parsys'}" data-sly-unwrap></div>  
            <li class="clear"></li>
        </ul>
    </section>  
</section>

Tag component which is dragged and dropped into the container parsys above:

<li data-sly-use.timelineTag="TimelineClass" class="event" href="#">
    <img style="width: 165px;" data-sly-test="${properties.outerImage}" alt="placeholder" src="${properties.outerImage}"/>
    <article>
        <h5>${properties.heading || 'Timeline heading'}</h5>
        <h4>${properties.subheading || 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sunt labore molestias perspiciatis reiciendis.'}</h4>
        <p>${properties.text || 'Sed molestie, mauris sit amet egestas malesuada, felis magna commodo urna, vel consequat lorem enim ac diam. Aenean eget ex vitae enim cursus facilisis ac feugiat nisl. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.'}</p>
        <img style="height: 130px;" data-sly-test="${properties.innerImage}" alt="" src="${properties.innerImage}" />
        <a data-sly-test="${properties.link}" class="az-sbButton" href="${properties.link}">${properties.linkText || 'More'}<span class="owi-az-linkIcon internal"></span></a>
    </article>
</li>

Several of the tag components are dragged and dropped into the parsys in the container and the result in wcmmode=disabled is the second ul shown above with the first item in the list surrounded by a div tag

5
You REALLY need to give the code surrounding the LI block, like the whole UL setup.Brenn
I have added the ul tags as you requestedsamwhite024

5 Answers

1
votes

I haven't worked with the Sightly stuff yet, but I have had success removing the extra divs by assigning the property "cq:noDecoration" (Boolean set to true) on the component in the JCR. Try that and see if it helps.

0
votes

if i understand you correctly and you want div.section.timelineTag to be here only in edit mode, then the code would be

<ul>
  <div data-sly-test="${wcmmode.edit}" class="section timelineTag">
0
votes

Use data-sly-unwrap. See this post and the referenced doc from adobe http://www.aemmastery.com/2015/04/24/remove-div-tags-sightly/

"data-sly-unwrap: Removes the host element from the generated markup while retaining its content."

Another option, set cq:htmlTag to "": http://dev.day.com/cemblog/en/experiencedelivers/2013/04/modify_the_auto-generateddivs.html

0
votes

As Rampant suggested but make the timeline ul part of the component and try setting cq:htmlTag to a "ul" and give it a class timeline: and you can still edit the component and it does not mess with the display. http://dev.day.com/cemblog/en/experiencedelivers/2013/04/modify_the_auto-generateddivs.html

0
votes

Possible workaround for the issue when you need conditional remove of the decoration tags in Sightly on example of edit / preview mode:

  1. Create two child components for your component ("parent-component") - "edit-view" and "preview-view".
  2. For "edit-view" component set cq:noDecoration="{Boolean}false"
  3. For "preview-view" component set cq:noDecoration="{Boolean}true"
  4. In parent-component.html add conditional rendering like:
 <sly data-sly-test="${isEditMode}">
      <sly data-sly-resource="${'editViewResourceName' @ resourceType='yourapp/components/parent-component/edit-view'}"></sly>
  </sly>   

<sly data-sly-test="${isPreviewMode}">
    <sly data-sly-resource="${'editViewResourceName' @ resourceType='yourapp/components/parent-component/preview-view'}"></sly>
</sly>

Tips:

  1. Add dialog only for "edit-view" component.
  2. For "preview-view" component you can keep only .content.xml and preview-view.html
  3. To avoid code duplication there is possibility to include "edit-view" into "preview-view" using construction like
<sly data-sly-resource="${currentNode.path @ resourceType='yourapp/components/parent-component/edit-view'}"></sly>