Hello Community Members,
Good Day!
I have a use case, I have a HTL file (present in the Dev, Stage and Prod instances) in which I have a particular HTL Snippet I want to get executed in AEM Stage and Dev instances only (Including Author and Publisher) and strictly not on the Production instance.
Is there a way to code this logic in HTL so that the HTL Snippet will only gets executed on the Dev and Stage instance.
Thank You.
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @arunpatidar
Thanks for sharing the above piece of information, however we can see the "slingSettingsService" is deprecated.
As mentioned by the Author of the post you have shared I will try the new method suggested by the author.
https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem-in-2023
Thank You.
Views
Replies
Total Likes
Hi @Nitesh-Chavan ,
Yes, you can control execution of HTL code based on the AEM environment (Dev, Stage, Prod) by making use of run modes and exposing them via a Sling Model or Use-API class to your HTL.
public class EnvironmentCheck extends WCMUsePojo {
private boolean isDevOrStage;
@Override
public void activate() {
SlingSettingsService slingSettings = getSlingScriptHelper().getService(SlingSettingsService.class);
Set<String> runModes = slingSettings.getRunModes();
isDevOrStage = runModes.contains("dev") || runModes.contains("stage");
}
public boolean isDevOrStage() {
return isDevOrStage;
}
}
<data-sly-use.envCheck="com.example.core.utils.EnvironmentCheck" />
<sly data-sly-test="${envCheck.devOrStage}">
<p>This is shown in Dev/Stage only.</p>
</sly>
Set run modes like this in your instance: -Dsling.run.modes=env
Try this and let me know if it works.
I will check this and I will get back to you on it.
Thank You.
Views
Replies
Total Likes
Hi @ShivamKumar ,
Thanks for sharing the above piece of information, however we can see the "slingSettingsService" is deprecated.
I am will try with the following option.
https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem-in-2023
Thank You.
Thanks for the information - I wasn’t aware it was deprecated. I’ll check that.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies