Determine runmode in Adobe CQ

后端 未结 7 910
渐次进展
渐次进展 2021-01-02 00:44

How do I programmatically know which run-mode the instance is running? I created a custom tag that provides the config depending on the instance run-mode, but I can not dete

7条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-02 01:30

    As Bertrand Delacretaz said it is the right way to check whether instance is Author or Publish. In jsp or java you could check like

    import  org.apache.sling.settings.SlingSettingsService
    Set runModes = sling.getService(SlingSettingsService.class).getRunModes();
    
    if (runModes.contains("author")) {
    } 
    

    Another way is using

    if (mode == WCMMode.EDIT) 
    {
    }
    

    But this approach will fail in case of Preview mode and wouldn't work.

提交回复
热议问题