design mode in slightly

Avatar

Avatar

Sandeep6

Avatar

Sandeep6

Sandeep6

11-11-2020

Hi Team,

${wcmmode.design} is giving false even in design mode.

Please help me to resolve the issue.

Aem version - 6.4

 

Thanks,

Sandeep.

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

snbaem

Avatar

snbaem

snbaem

12-11-2020

Hi @san can you try the code line below ? Otherwise what you have mentioned seems like should work too.. Below kind of logic seems to work for me

 

//Display test1 if in design mode or test2 in edit mode
<sly data-sly-test.author="${wcmmode.design}">test1</sly>
<sly data-sly-test.author="${wcmmode.edit}">test2</sly>

 

Answers (4)

Answers (4)

Avatar

Avatar

snbaem

Avatar

snbaem

snbaem

13-11-2020

@Sandeep6 

Using below in java also gives "edit" for value of wcmMode when loaded the page in design mode.

 

WCMMode wcmMode = WCMMode.fromRequest(slingRequest); 

 

Also needed to refresh the page for the model to be invoked.

Something that worked was trying similar to below

 

slingRequest.getCookie("cq-editor-layer.page").getValue()

 

 
 

 

 

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Answer

831

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Answer

831
Arun_Patidar
MVP

12-11-2020

are you able to see the design mode set in cookies?

could you try with java API https://helpx.adobe.com/experience-manager/6-4/sites/developing/using/reference-materials/javadoc/co...

Is there anywany to get design mode in slightly?

Hi @Arun_Patidar ,

I have tried using java also. still no luck. Please find below for code. Here I am getting wcmmode as. EDIT even in design mode.

 

@Model(adaptables = SlingHttpServletRequest.class)
public class WCMModel {

private static Logger logger = LoggerFactory.getLogger(WCMModel.class);
@Inject
private SlingHttpServletRequest httpServletRequest;

private boolean isDesign;

@PostConstruct
protected void init() {
logger.info("wcmmode = " + WCMMode.fromRequest(httpServletRequest));
if (WCMMode.DESIGN == WCMMode.fromRequest(httpServletRequest)) {
isDesign = true;
}
logger.info("wcmmode 2= " + WCMMode.valueOf(String.valueOf(httpServletRequest.getAttribute(WCMMode.REQUEST_ATTRIBUTE_NAME))));
if(WCMMode.DESIGN == WCMMode.valueOf(String.valueOf(httpServletRequest.getAttribute(WCMMode.REQUEST_ATTRIBUTE_NAME)))){
isDesign = true;
}
}

public boolean isDesign() {
logger.info("wcmmode123 = " + isDesign);
return isDesign;
}

 

Capture.PNG

 

Thanks,

Sandeep.

@Sandeepif it help this backend logic works for me 

 

@Model(adaptables = {SlingHttpServletRequest.class, Resource.class }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)

public class TestModel {

    private static final Logger LOG = LoggerFactory.getLogger(TestModel.class);

    @Inject
    private Resource resource;

    @SlingObject
    private SlingHttpServletRequest slingRequest;

    @ValueMapValue(name = "id", injectionStrategy = InjectionStrategy.OPTIONAL)
    private String testid;

   

    @PostConstruct
    protected void initModel() {
       
        if (resource != null) {
           
            WCMMode wcmMode = WCMMode.fromRequest(slingRequest);
            if (wcmMode != null) {
                if (wcmMode == WCMMode.EDIT) {
                    
                    // EDIT logic
                } else if (wcmMode == WCMMode.DESIGN) {
                    //DESIGN logic
                }
            } else {
                LOG.warn("wcmmode is null. Not processing Resource at: " + resource.getPath());
            }
        }
    }
}

 

. The difference I see is @SlingObject annotation. On debug do you get the sling request object? 

Update: I was only using wcmmode.edit that's why it seemed to work. But actually for wcmmode.design the value is incorrect

It is not working for me as well and I noticed the cookies are not getting updated but updating in classic mode.

 

Arun_Patidar_0-1605296593215.png

 

Arun_Patidar_1-1605296625517.png

 

Checked after seeing @Arun's comment. I am seeing the cookie state same as him. wcmmode is still edit when switched to Design mode. If clicked on preview and then design, then the wcmmode is preview which is still incorrect.
Hi arun, Do we have any workaround for this?

Avatar

Avatar

TUmesh

Avatar

TUmesh

TUmesh

11-11-2020

I don't think so we can get design mode in AEM6.4

Avatar

Avatar

sureshd71454102

Avatar

sureshd71454102

sureshd71454102

11-11-2020

<sly data-sly-test="${wcmmode.design}"></sly> - this syntax should work

can you give your complete html source here