Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

AEM Sightly - Check if edit mode

LaMind3
Level 2
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>
AEM 6.5
1 Accepted Solution
Manjunath_K
Correct answer by
Community Advisor
Community Advisor

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
Manjunath_K
Correct answer by
Community Advisor
Community Advisor

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

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

santhosh_kumark
Community Advisor
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

 

Arun_Patidar
Community Advisor
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}

 

VeenaK
Level 3
Level 3

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