Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

design mode in slightly

Avatar

Level 5

Hi Team,

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

Please help me to resolve the issue.

Aem version - 6.4

 

Thanks,

Sandeep.

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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>

 

View solution in original post

12 Replies

Avatar

Community Advisor

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

can you give your complete html source here

Avatar

Level 5
<sly data-sly-test="${wcmmode.design}"> <h4>XYZ</h4> </sly>

Avatar

Community Advisor

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

Avatar

Level 5

Is there anywany to get design mode in slightly?

Avatar

Level 5

Hi @arunpatidar ,

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.

Avatar

Community Advisor

@Deleted Accountif 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

Avatar

Community Advisor

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

 



Arun Patidar

Avatar

Community Advisor
Checked after seeing @Deleted Account'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.

Avatar

Correct answer by
Community Advisor

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>

 

Avatar

Community Advisor

@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()