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.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @ravindrard
You need to use author runmode here.
example : https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem
Hi @ravindrard
Please check https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-add-the-author-edit...
<style data-sly-test.author="${wcmmode.preview || wcmmode.edit}">
Hi @ravindrard
You need to use author runmode here.
example : https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem
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./content
. This indicates the author instance./content/preview
. This signifies the preview 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 !
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.
@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.
Views
Likes
Replies