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

AEM Sightly - Check if edit mode

Avatar

Level 2

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

Topics help categorize Community content and increase your ability to discover relevant content.

6.5
1 Accepted Solution

Avatar

Correct answer by
Level 8

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

View solution in original post

5 Replies

Avatar

Correct answer by
Level 8

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

Avatar

Community Advisor

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!

Avatar

Community Advisor

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

 

Avatar

Community Advisor

As mentioned by @Manjunath_K${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}

 



Arun Patidar

Avatar

Level 5

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