How to use cq:noDecorator property in cq5 , can the default 'div' tag be changed to other block tags

孤街醉人 提交于 2020-01-14 03:50:09

问题


I need to remove decorator 'div' tags added around components by CQ5 for few select components. They can be part of the mark up in author mode, but it should not be present in the final mark up on publish.


回答1:


To change the default div tags to something else , use cq:htmlTag nodes in your components. This lets you modify the tag , classes and id associated with the decorator tag.

  • Create cq:htmlTag node [primaryType:nt:unstructured] under your component.
  • Add cq:tagName property [type:String] with the tag to be used as value.
  • Add class property [type:String] with class(es) to be added to the enclosing tag **
  • Add id property [type:String] with id to be added to the enclosing tag

    ** CQ will add an extra class of its own.

Source : http://experiencedelivers.adobe.com/cemblog/en/experiencedelivers/2013/04/modify_the_auto-generateddivs.html




回答2:


You can wrap them in an if statement. Using JSTL:

<%
if (WCMMode.fromRequest(request) == WCMMode.EDIT) {
%>
<div>
<%
}
%>

Of course you shouln't use java code in the JSP directly, but rather put it in a request variable and use JSTL:

<c:if test="${isEditMode}">
<div>
</c:if>

If you want to get rid of the automatic generated divs, you would need to combine this with the noDecorator property and add the edit dialog script by other means within your optional divs.




回答3:


You can also use this

<%
   if (WCMMode.fromRequest(request) != WCMMode.EDIT && 
        WCMMode.fromRequest(request) != WCMMode.DESIGN) 
   {
       IncludeOptions.getOptions(request, true).forceSameContext(Boolean.TRUE);
   }
%>


来源:https://stackoverflow.com/questions/27415626/how-to-use-cqnodecorator-property-in-cq5-can-the-default-div-tag-be-changed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!