How to programmatically enable / disable cq:noDecoration? | Community
Skip to main content
June 26, 2020
Solved

How to programmatically enable / disable cq:noDecoration?

  • June 26, 2020
  • 3 replies
  • 2371 views

Hello All,

I have a problem where the overall page renders HTML elements as expected in the publisher when cq:noDecoration is set to "true" on a given component.

However, when cq:noDecoration is set to "true", I cannot edit and make any changes my component; the dialogue does not show. When I set the value to false, it works again, but I the publisher needs the value cq:noDecoration=true.

Is there a nice way for me to programmatically set cq:noDecoration to true only on "author mode"?

Requirement:

  • only set cq:noDecoration to "true" in author mode.
  • only set cq:noDecoration to "false" that is not author mode. 

My Component is JSP.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Vaibhavi_J

Hi @17378453 

 

You can do a runmode check to know if the instance is author or publisher. You can set the property accordingly. 

 

There are many ways to do. 

Example:

JSP:

If you need to check runmode in jsp. (But will suggest not to add scriptlet, you can move it to taglib and get the result) 

Please use below code:- <% pageContext.setAttribute("runModes", sling.getService(SlingSettingsService.class).getRunModes().toString()); %>

Slightly:

Pretty simple to do

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-now-publish-mode-edit-mode-in-htl/qaq-p/263938

3 replies

Vaibhavi_J
Vaibhavi_JAccepted solution
Level 7
June 26, 2020

Hi @17378453 

 

You can do a runmode check to know if the instance is author or publisher. You can set the property accordingly. 

 

There are many ways to do. 

Example:

JSP:

If you need to check runmode in jsp. (But will suggest not to add scriptlet, you can move it to taglib and get the result) 

Please use below code:- <% pageContext.setAttribute("runModes", sling.getService(SlingSettingsService.class).getRunModes().toString()); %>

Slightly:

Pretty simple to do

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-now-publish-mode-edit-mode-in-htl/qaq-p/263938

raghavc
Level 4
June 26, 2020

In addition to the runmode check suggested by @vaibhavi_j , please use IncludeOptions to enable/disable decoration tags. Please refer to the below link

https://www.codermag.net/2016/02/remove-component-wrapper-divs-in-cqaem.html

Asutosh_Jena_
Community Advisor
Community Advisor
June 27, 2020

@17378453 Looks like you want to hide the component div and it can be achieved by using the below piece of code.

 

Add the below code into headlibs.html/similar area.

 

<%
if (WCMMode.fromRequest(request) != WCMMode.EDIT && WCMMode.fromRequest(request) != WCMMode.DESIGN) {
slingRequest.setAttribute(ComponentContext.BYPASS_COMPONENT_HANDLING_ON_INCLUDE_ATTRIBUTE, false);
}
%>

Add the below code into footlibs.html/similar area.

<%
if (WCMMode.fromRequest(request) != WCMMode.EDIT && WCMMode.fromRequest(request) != WCMMode.DESIGN) {
slingRequest.removeAttribute(ComponentContext.BYPASS_COMPONENT_HANDLING_ON_INCLUDE_ATTRIBUTE);
}
%>