How to programmatically enable / disable cq:noDecoration?

karthik4

26-06-2020

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.

Accepted Solutions (1)

Accepted Solutions (1)

vaibhavi_235640

26-06-2020

Hi @karthik4 

 

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-ed...

Answers (2)

Answers (2)

asutoshj7327906

26-06-2020

@karthik4 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);
}
%>