How to now publish mode & edit mode in HTL?

Avatar

Avatar
Validate 10
Level 3
bhoang
Level 3

Likes

11 likes

Total Posts

92 posts

Correct reply

2 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 10
View profile

Avatar
Validate 10
Level 3
bhoang
Level 3

Likes

11 likes

Total Posts

92 posts

Correct reply

2 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 10
View profile
bhoang
Level 3

09-04-2018

Hi,

I want to check publish mode & edit mode in the HTL. Example: in the Article component article.html I want to check if "publish mode" print "ABC", If "edit mode" print "XYZ"

How to do that?

Thanks & Best regards,

BienHV

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 50
Level 6
Techaspect_Solu
Level 6

Likes

63 likes

Total Posts

150 posts

Correct reply

79 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Boost 50
Level 6
Techaspect_Solu
Level 6

Likes

63 likes

Total Posts

150 posts

Correct reply

79 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 25
Boost 10
View profile
Techaspect_Solu
Level 6

09-04-2018

Hi,

You can do it by using following lines of code

<sly data-sly-test="${wcmmode.edit}">

<h4>XYZ</h4>

</sly>

<sly data-sly-test="${wcmmode.disabled}">

<h4>ABC</h4>

</sly>

OR

<sly data-sly-test.author="${wcmmode.edit || wcmmode.design }">

<h4>XYZ</h4>

</sly>

<sly data-sly-test="${!author}">

<h4>ABC</h4>

</sly>

For deeper knowledge on HTL block statements refer to following link;

HTL Block Statements

We hope this information helps!

Regards,

TechAspect Solutions

Answers (4)

Answers (4)

Avatar

Avatar
Validate 10
Level 3
bhoang
Level 3

Likes

11 likes

Total Posts

92 posts

Correct reply

2 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 10
View profile

Avatar
Validate 10
Level 3
bhoang
Level 3

Likes

11 likes

Total Posts

92 posts

Correct reply

2 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 10
View profile
bhoang
Level 3

10-04-2018

Thank you so much,

Avatar

Avatar
Springboard
Level 2
Amit-Tiwari
Level 2

Likes

10 likes

Total Posts

31 posts

Correct reply

4 solutions
Top badges earned
Springboard
Ignite 3
Ignite 1
Validate 1
Establish
View profile

Avatar
Springboard
Level 2
Amit-Tiwari
Level 2

Likes

10 likes

Total Posts

31 posts

Correct reply

4 solutions
Top badges earned
Springboard
Ignite 3
Ignite 1
Validate 1
Establish
View profile
Amit-Tiwari
Level 2

10-04-2018

yes,

you need to use below js to get runmode:

Read AEM runmodes from Sightly · GitHub (here you can find it in detail)

  Lets say it runmode.js

var SlingSettingsService = Packages.org.apache.sling.settings.SlingSettingsService;

use(function () {

     // Get runmodes and transform them into an object that is easier to read for Sightly

     var runmodesObj = {};

     var runmodesSet = sling.getService(SlingSettingsService).getRunModes();

     var iterator = runmodesSet.iterator();

     while (iterator.hasNext()) {

         runmodesObj[iterator.next()] = true;

     }

    return {

         runmodes: runmodesObj

     }

});

HTL part

<sly data-sly-use.logic="runmode.js">

<p>Current runmodes: ${logic.runmodes}</p>// it will gives you all runmodes like

Current runmodes: crx3,author,samplecontent,crx3tar

<sly data-sly-test="${logic.runmodes.author}">

in author

</sly>

<sly data-sly-test="${logic.runmodes.publish}">

in publish

</sly>

Avatar

Avatar
Validate 10
Level 3
bhoang
Level 3

Likes

11 likes

Total Posts

92 posts

Correct reply

2 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 10
View profile

Avatar
Validate 10
Level 3
bhoang
Level 3

Likes

11 likes

Total Posts

92 posts

Correct reply

2 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 10
View profile
bhoang
Level 3

09-04-2018

Thank you for your help.

I know that solutions. Do you have other solution? Does AEM have publish mode?

Avatar

Avatar
Springboard
Level 2
Amit-Tiwari
Level 2

Likes

10 likes

Total Posts

31 posts

Correct reply

4 solutions
Top badges earned
Springboard
Ignite 3
Ignite 1
Validate 1
Establish
View profile

Avatar
Springboard
Level 2
Amit-Tiwari
Level 2

Likes

10 likes

Total Posts

31 posts

Correct reply

4 solutions
Top badges earned
Springboard
Ignite 3
Ignite 1
Validate 1
Establish
View profile
Amit-Tiwari
Level 2

09-04-2018

<sly data-sly-test.author="${wcmmode.edit || wcmmode.design}"/>

<sly data-sly-test="${!author}">

on publish

</sly>

<sly data-sly-test="${author}">

on author

</sly>