AEM Sightly - Check if edit mode

Avatar

Avatar
Validate 1
Level 1
LaMind3
Level 1

Like

1 like

Total Posts

15 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
LaMind3
Level 1

Like

1 like

Total Posts

15 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
LaMind3
Level 1

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>

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back 3
MVP
Manjunath_K
MVP

Likes

140 likes

Total Posts

188 posts

Correct reply

61 solutions
Top badges earned
Give Back 3
Give Back
Boost 50
Boost 5
Boost 3
View profile

Avatar
Give Back 3
MVP
Manjunath_K
MVP

Likes

140 likes

Total Posts

188 posts

Correct reply

61 solutions
Top badges earned
Give Back 3
Give Back
Boost 50
Boost 5
Boost 3
View profile
Manjunath_K
MVP

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)

Avatar

Avatar
Contributor
Level 2
VeenaK
Level 2

Likes

18 likes

Total Posts

15 posts

Correct reply

3 solutions
Top badges earned
Contributor
Shape 1
Give Back
Boost 5
Boost 3
View profile

Avatar
Contributor
Level 2
VeenaK
Level 2

Likes

18 likes

Total Posts

15 posts

Correct reply

3 solutions
Top badges earned
Contributor
Shape 1
Give Back
Boost 5
Boost 3
View profile
VeenaK
Level 2

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

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,442 likes

Total Posts

3,318 posts

Correct reply

941 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,442 likes

Total Posts

3,318 posts

Correct reply

941 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

11-10-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}

 

Avatar

Avatar
Establish
MVP
santhosh_kumark
MVP

Likes

99 likes

Total Posts

111 posts

Correct reply

38 solutions
Top badges earned
Establish
Validate 1
Give Back 3
Give Back
Boost 50
View profile

Avatar
Establish
MVP
santhosh_kumark
MVP

Likes

99 likes

Total Posts

111 posts

Correct reply

38 solutions
Top badges earned
Establish
Validate 1
Give Back 3
Give Back
Boost 50
View profile
santhosh_kumark
MVP

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

 

Avatar

Avatar
Establish
MVP
Ravi_Pampana
MVP

Likes

197 likes

Total Posts

243 posts

Correct reply

75 solutions
Top badges earned
Establish
Contributor
Shape 1
Ignite 5
Ignite 3
View profile

Avatar
Establish
MVP
Ravi_Pampana
MVP

Likes

197 likes

Total Posts

243 posts

Correct reply

75 solutions
Top badges earned
Establish
Contributor
Shape 1
Ignite 5
Ignite 3
View profile
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!