Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

Image Metadata causing 500 error

Avatar

Level 4

I am trying to implement the image metadata inside the module with the following code. 

<sly data-sly-use.myImg="${properties.laptopReference}/jcr:content/metadata">   
<img src="${properties.laptopReference}" class="cover lazyloaded" alt="${myImg.valueMap['dc:title']}">
</sly>

It is working, but if the image is not there it is giving 500 page error.

 

Any idea to resolve this error?

1 Accepted Solution

Avatar

Correct answer by
Level 4

Finally, I resolved the issue. I wrote a if condition to check and print the image metadata and it was working good. Thanks for helping out guys.

View solution in original post

4 Replies

Avatar

Community Advisor

Hi @Ameen_Dev,

You can verify if the image is there using the data-sly-test.

<sly data-sly-test="${properties.laptopReference}"
  data-sly-use.myImg="${properties.laptopReference}/jcr:content/metadata">   
  <img src="${properties.laptopReference}" class="cover lazyloaded"
    alt="${myImg.valueMap['dc:title']}">
</sly>

 

Avatar

Community Advisor

You can first check if laptopReference exist or not, use data-sly-test to validate, if true then execute your logic.

 

<sly data-sly-test="${properties.laptopReference}"
  data-sly-use.myImg="${properties.laptopReference}/jcr:content/metadata"> 
<!-- add your logic--------->
//if true then your logic will work otherwise it will not  
  <img src="${properties.laptopReference}" class="cover lazyloaded"
    alt="${myImg.valueMap['dc:title']}">
</sly>

 

Avatar

Level 4

I already tried that. even after adding the test condition it was not working. It seems like, it is looking for the metadata properties which are not filled up.

Avatar

Correct answer by
Level 4

Finally, I resolved the issue. I wrote a if condition to check and print the image metadata and it was working good. Thanks for helping out guys.