As a supplement to the design document, please do
not display it in the Author environment (editor, view as published screens), but operate only in the Publish environment .
Solved! Go to Solution.
Views
Replies
Total Likes
Can you replace with below in your sightly .
<div data-sly-test="${runMode.hasRunMode }">
Hi @ferosekhan ,
You can setup run mode configurations for your component, and fetch that logic in HTL to check whether you would like to have it displayed or not.
eg. for run modes - https://www.techinnovia.com/run-modes/
Hope that helps you!
Regards,
Santosh
You can do this by detecting AEM runmode
If publish show otherwise hide
https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem
any other example? a
little bit confusing!
@arunpatidar is there a way we can use runmodes in cq:component node on property component group in case I want to have different groups on different envs say i want to .hidden on PROD?
Hi,
It is not possible , however you can hide the dialog's content root node using rendercondition.
It can be done by fetching runmode from AEM instance. you can hide the component afterwards.
TO fetch the runmode, please refer below thread
I hope it helps.
You can add a new field in your dialog as runmode and you can input as publish.
Then in your sightly you an call as ,
<sly data-sly-use.runMode= "com.sourcedcode.core.models.utils.RunModeHelper ;">
<div data-sly-test="${runMode.getHasRunMode}">
// you can write your component logic here.
</div>
package com.sourcedcode.core.models.utils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.Default;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.OSGiService;
import org.apache.sling.models.annotations.injectorspecific.RequestAttribute;
import org.apache.sling.settings.SlingSettingsService;
import javax.annotation.PostConstruct;
@Model(adaptables = SlingHttpServletRequest.class)
public class RunModeHelper {
@OSGiService
private SlingSettingsService slingSettingsService;
@RequestAttribute
@Default(values = "null")
private String runmode;
private boolean hasRunMode = false;
@PostConstruct
public void init() {
String runModes = slingSettingsService.getRunModes().toString();
hasRunMode = runModes.contains(runmode);
}
public boolean getHasRunMode() {
return hasRunMode;
}
}
source : https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem
Thanks,
Siva
code working good but publish environment also not showing!
Can you replace with below in your sightly .
<div data-sly-test="${runMode.hasRunMode }">
@ferosekhan You just need to get the runmode and use data-sly-test to match it using a variable isRunModePublish.
You can find your run modes in: http://localhost:4502/system/console/status-slingsettings
Using Java:
slingSettingsService.getRunModes()
Using Slightly:
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
}
});
and use HTL
<div data-sly-use.logic="logic.js">
<p>Current runmodes: ${logic.runmodes}</p>
<p data-sly-test="${logic.runmodes.publish}">publish runmode</p>
</div>
try in a different manner, but the expected result does not come.
Views
Like
Replies