Expand my Community achievements bar.

SOLVED

How to programmatically enable / disable cq:noDecoration?

Avatar

Level 2

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.

1 Accepted Solution

Avatar

Correct answer by
Level 9

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

View solution in original post

3 Replies

Avatar

Correct answer by
Level 9

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

Avatar

Level 5

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

Avatar

Community Advisor

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