In AEM sightly check author or preview or publish instnace | Community
Skip to main content
April 12, 2024
Solved

In AEM sightly check author or preview or publish instnace

  • April 12, 2024
  • 4 replies
  • 1960 views

We have a requirement to load an experience fragment in aem author instance (in all modes - edit, preview & disabled) using data-sly-resource approach where as in aem preview & publisher instances we want to load the experience fragment using Server Side Include (SSI) approach.

 

To achieve this I need to identify in the AEM Instance (author, preview or publish) in AEM Sightly Code using data-sly-test approach.

 

Please suggest me how to implement it.

 

@arunpatidar

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

Hi @ravindrard 
You need to use author runmode here.

example : https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem 

4 replies

arunpatidar
Community Advisor
Community Advisor
April 12, 2024
arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
April 12, 2024
Arun Patidar
partyush
Community Advisor
Community Advisor
April 13, 2024

Hi @ravindrard 

 

AEM Sightly provides access to the Sling request object through the properties variable. You can leverage the request object to identify the instance based on the context path.

<div data-sly-test="${properties.resourceResolver.descriptor.path == '/content' ? 'author' : properties.resourceResolver.descriptor.path.contains('/content/preview') ? 'preview' : 'publish'}"> </div>

 

Explanation:

  • properties.resourceResolver.descriptor.path provides the context path of the current request.
  • The code checks if the path starts with /content. This indicates the author instance.
  • It then checks if the path contains /content/preview. This signifies the preview instance.
  • Any other path is assumed to be the publish instance.

 

Or  Leverage Sling Models Exporter API (Optional):

If you're using Sling Models Exporters, you can access the exporter instance within your Sightly component. The exporter might provide properties or methods to identify the instance.

Example (if your exporter has an isAuthor property):

<div data-sly-test="${exportModel.isAuthor ? 'author' : exportModel.isPreview ? 'preview' : 'publish'}"> </div>

 

The first approach using the Sling request API is the most common and reliable way to identify the instance within Sightly code.

 

Thanks ! 🙂

 

Mahedi_Sabuj
Community Advisor
Community Advisor
April 14, 2024

Based on my understanding, your intention is to implement Sling Dynamic Include (SDI) exclusively on the Publish Instance while keeping the Author Instance unchanged. To achieve this, you can place the org.apache.sling.dynamicinclude.Configuration~aem-demo.cfg.json file only in the config.publish directory. This ensures that SDI will affect only the Publish Instance.

Mahedi Sabuj
EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
April 18, 2024

@ravindrard Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Esteban Bustamante