AEM Sightly - Check if edit mode

LaMind3

09-10-2020

I am working AEM 6.5 , I want to add a functionality on preview mode alone, not on edit mode . I tried adding below condition . But its not working. Can someone help me out here?

<sly data-sly-test="${wcmmode.edit}">
EDIT MODE:
</sly>
<sly data-sly-test="${wcmmode.disabled}">
<div>some code here..</div>
</sly>
AEM 6.5

Accepted Solutions (1)

Accepted Solutions (1)

Manjunathh

09-10-2020

Hi @LaMind3,

You can use ${wcmmode.preview} as mentioned below to add any code specific to preview mode only.

 

<div data-sly-test="${wcmmode.preview}">
<h1>Preview Mode</h1>
</div>

 

-Manjunath

Answers (4)

Answers (4)

VeenaK

11-10-2020

@LaMind3  similar case has been addressed at https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-add-the-author-edit... please check.

Also, as preview mode demands a page refresh, can use ${wcmmode.preview || wcmmode.edit} for your case. If that conditional output has to work on publish mode then please add ${wcmmode.disabled}.

Arun_Patidar

MVP

11-10-2020

As mentioned by @Manjunathh${wcmmode.preview} will work but if you are in edit mode and click on preview then it will not work and there is a reason for that. you need to reload the page after clicking on preview then it will show content which is based on preview condition. The same applies for switching from preview to edit mode.

 

I would suggest to include edit mode as well in the condition

${wcmmode.preview || wcmmode.edit}

 

santhosh_kumark

10-10-2020

Hi @LaMind3 ,

 

Try with the test condition as below:

</sly>
<slydata-sly-test="${!wcmmode.edit || wcmmode.disabled}">
<h1>Content only showed on preview/published mode</h1>
</sly>

 

Regards,

Santosh

 

Ravi_Pampana

MVP

09-10-2020

Hi,

 

Try "wcmmode.preview" but when we change from edit mode to preview there wont be page refresh and this will not work as intended. You need to do a page refresh on selecting preview mode.

 

Hope this helps!