AEM Sightly - Check if edit mode | Community
Skip to main content
Level 2
October 9, 2020
Solved

AEM Sightly - Check if edit mode

  • October 9, 2020
  • 5 replies
  • 11870 views

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>
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Manjunath_K

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

5 replies

Manjunath_K
Manjunath_KAccepted solution
Level 7
October 9, 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

Ravi_Pampana
Community Advisor
Community Advisor
October 9, 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!

santhosh_kumark
Level 6
October 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

 

arunpatidar
Community Advisor
Community Advisor
October 11, 2020

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
Level 4
October 11, 2020

@lamind3  similar case has been addressed at https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-add-the-author-edit-mode-condition-in-sightly-htl-for/qaq-p/330826 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}.