How to now publish mode & edit mode in HTL?

Avatar

Avatar

bhoang

Avatar

bhoang

bhoang

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

Techaspect_Solu

Avatar

Techaspect_Solu

Techaspect_Solu

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

bhoang

Avatar

bhoang

bhoang

10-04-2018

Thank you so much,

Avatar

Avatar

amitkrt

Avatar

amitkrt

amitkrt

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

bhoang

Avatar

bhoang

bhoang

09-04-2018

Thank you for your help.

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

Avatar

Avatar

amitkrt

Avatar

amitkrt

amitkrt

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>