When Asset expires, display the default image path | Community
Skip to main content
Level 2
November 13, 2024
Solved

When Asset expires, display the default image path

  • November 13, 2024
  • 3 replies
  • 1079 views

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.

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

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

 


Hi @kamaraj_aem 
Please check below - https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/extend-graphql-content-fragment-model-result/m-p/613865 

3 replies

arunpatidar
Community Advisor
Community Advisor
November 13, 2024

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
Level 2
November 18, 2024

@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!

arunpatidar
Community Advisor
Community Advisor
November 18, 2024

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
MukeshYadav_
Community Advisor
Community Advisor
November 13, 2024

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-html-img-is-not-vali

Thanks

kautuk_sahni
Community Manager
Community Manager
November 25, 2024

@kamaraj_aem Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!

Kautuk Sahni