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

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
Validate 1
Level 2
amitkrt
Level 2

Likes

10 likes

Total Posts

31 posts

Correct Reply

4 solutions
Top badges earned
Validate 1
Establish
Give Back 3
Give Back
Boost 5
View profile

Avatar
Validate 1
Level 2
amitkrt
Level 2

Likes

10 likes

Total Posts

31 posts

Correct Reply

4 solutions
Top badges earned
Validate 1
Establish
Give Back 3
Give Back
Boost 5
View profile
amitkrt
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
Validate 1
Level 2
amitkrt
Level 2

Likes

10 likes

Total Posts

31 posts

Correct Reply

4 solutions
Top badges earned
Validate 1
Establish
Give Back 3
Give Back
Boost 5
View profile

Avatar
Validate 1
Level 2
amitkrt
Level 2

Likes

10 likes

Total Posts

31 posts

Correct Reply

4 solutions
Top badges earned
Validate 1
Establish
Give Back 3
Give Back
Boost 5
View profile
amitkrt
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>