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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

How to now publish mode & edit mode in HTL?

Avatar

Level 4

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

1 Accepted Solution

Avatar

Correct answer by
Level 7

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

View solution in original post

6 Replies

Avatar

Correct answer by
Level 7

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

Avatar

Level 4

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

Avatar

Level 4

Thank you for your help.

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

Avatar

Level 4

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>