Search code examples
aemsightly

How to check if child component resource exist or not using Sightly in AEM?


my component has an embedded image component inside of it, i need to show image only if image component is authored,

Component Code:

<div class="col-md-4">
<sly data-sly-resource="${'image' @ resourceType='test/components/content/image'}"></sly>
</div>

So i need to check resource of embedded image component authored or not

i know we can do this in Java, but how to do this in Sightly?


Solution

  • This can be doable ,using ${resource['image/jcr:primaryType']},

    here image is child component

    <sly data-sly-test="${resource['image/jcr:primaryType']}">
    <div class="col-xs-5 col-md-4">
    <sly data-sly-resource="${'image' @ resourceType='test/components/content/image'}"></sly>
    </div>
    </sly>