Expand my Community achievements bar.

When Asset expires, display the default image path

Avatar

Level 2

Hello Team,

In AEM Cloud, I want to display a default image on my page when any asset has expired.

I know that the DAM expiry job unpublishes the asset from the publish instance. I tried to write a filter, but it did not fulfill my requirement.

Please let me know if there is any way to meet my requirement.

Thank you in advance.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

6 Replies

Avatar

Community Advisor

Hi @Kamaraj_AEM 

One way for implementing a default or fallback image in AEM using a Sling Model, you can write custom logic in the model to check if an image resource is present. If the image is missing, the model can then refer to a predefined default image resource as a fallback.

 



Arun Patidar

Avatar

Level 2

@arunpatidar thanks for your reply. 
Most of the assets are used in content fragments and exposed to third parties using Graphql URL.

So I am looking for a common solution both pages and content fragments.

Thanks!

Avatar

Community Advisor

HI @Kamaraj_AEM 
Maybe you can set default image at config level which you might be exposing via GraphgQL , if not then you need to extend graphQL response to add another field.



Arun Patidar

Avatar

Level 2

I didn't understand your point. Can you please explain in a bit more depth with an example?

 

Avatar

Community Advisor

Hi @Kamaraj_AEM ,

We can use onerror attributes. The onerror event is triggered if an error occurs while loading an external file (e.g. a document or an image).

 

<img src="foo.jpg" onerror="this.src='fallback/image.jpg';this.onerror='';">

 

Reference https://stackoverflow.com/questions/980855/inputting-a-default-image-in-case-the-src-attribute-of-an...

Thanks