AEM Run Modes

Run modes play an important role in aem. Run modes maps to an AEM instance.
They are useful in case we want to provide diff configurations & logic based on the environments.
Refer below link to learn about run modes in details.

https://helpx.adobe.com/in/experience-manager/6-4/sites/deploying/using/configure-runmodes.html

How to check the run mode of an AEM Server.

  • Go to Status tab in Navigation and click on sling settings option.

  • Here you can see the Run Modes

Direct link for accessing the same is http://localhost:4502/system/console/status-slingsettings

To access AEM run modes in Sightly(HTL):-

There is a way to read run modes in sightly which can be further used to write your logic based on  environments.
Suppose there is a use-case where you want to display some warnings/messages based on the environment then you can easily do it in sightly without writing any logic in sling models or wcmusepojo.
Here we are using server side javascript logic to read run modes using SlingSettingsService.

runmodes.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
    }
});


help.html


<div data-sly-use.runmodes="runmodes.js" data-sly-list= ${runmodes.runmodes}> 
    <p>Runmodes: ${item}</p>
</div>
 <div data-sly-use.rmodes="runmodes.js" data-sly-list.runmode= ${rmodes.runmodes}>
        <sly data-sly-test.selector="${runmode=='dev'}">
  <p> This is Development environment!</p>
</sly>
<sly data-sly-test.selector="${runmode=='uat'}">
  <p> This is UAT environment!</p>
</sly>
<sly data-sly-test.selector="${runmode=='qa'}">
  <p> This is QA environment!</p>
</sly>
<sly data-sly-test.selector="${runmode=='prod'}">
  <p> This is Production environment!</p>
</sly>
 </div>




Comments

Popular posts from this blog

AEM Scheduler

AEM Sling Servlet

Event Handling in AEM