remove decoration tags aem sightly
Asked Answered
G

5

6

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

Gassaway answered 2/2, 2015 at 16:54 Comment(2)
You REALLY need to give the code surrounding the LI block, like the whole UL setup.Cullan
I have added the ul tags as you requestedGassaway
L
1

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.

Lamelliform answered 2/2, 2015 at 21:48 Comment(3)
Thanks for your response, however this will remove the decoration tags in edit and design mode as well and hence I will not be able to update the components in edit mode.Gassaway
Wow. I have finally integrated my site into 6.0 and am seeing the exact same problem you've described. If I come across an answer, I'll share it.Lamelliform
This only works for new components until you reload the page. After reload they're 'readonly'.Siltstone
G
0

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">
Galloon answered 5/2, 2015 at 9:29 Comment(4)
Thanks for the response, these div tags are generated automatically by AEM and therefore we cannot remove them in the HTML markup because they do not exist.Gassaway
can you edit your question with the component you are using, and the code you use to integrate it?Galloon
@Gassaway basically i think you should show the ul block sightly code because you just show the li block.Galloon
sorry for the delay but I have added the ul tagGassaway
C
0

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

Cullan answered 24/4, 2015 at 6:59 Comment(6)
Thanks for the comments. However these Div tags are automatically generated by AEM and not within the code. Therefore it is not possible to use "data-sly-unwrap".Gassaway
We could really use more data about how you are setting this up and why you only want to remove this in publish. I feel like you are going down a bad path. I've updated my original answer with another option using cq:htmlTagCullan
Hi, I just re-checked this and you are correct. This works! if you add a cq:htmlTag of jcr:primaryType = nt:unstructured with an element cq:tagName = String = "", then the automatically generated tags are removed. Thank you so much!!!Gassaway
Glad to help :) Please just upvote so that others find this answer:DCullan
Sorry but false alarm! This does remove all of the decoration tags as desired but it removes the tags during the edit mode as well. This makes the component difficult or impossible to edit for the author. For this reason it cannot be accepted as the correct answer. Sorry.Gassaway
That's a CSS/positioning issue. You can solve it that way. You will need to set styles on the parent. It also depends on if you are using Touch UI or classic.Cullan
M
0

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

Metric answered 26/5, 2015 at 20:16 Comment(0)
T
0

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>
Teetotal answered 7/10, 2016 at 11:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.