elikem
4/30/2016 - 11:18 PM

Read AEM runmodes from Sightly

Read AEM runmodes from Sightly

<div data-sly-use.logic="logic.js">
    <p>Current runmodes: ${logic.runmodes}</p>
    <p data-sly-test="${logic.runmodes.samplecontent}">samplecontent runmode</p>
</div>
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
    }
});