How do I insert a fallback photo if my entity doesn't have a photo?

I’d like to add a fallback image (like the silhouette attached or the business logo) in case a person entity is missing a photo. How can I do that so that I don’t have to individually update their headshots?


1 Like

Hi Hannah,

You can use a null checker to set behavior if a field’s value is not set. This is covered in the Defining New Cards unit.

Here’s an example for your use case:

image: profile.headshot ? Formatter.image(profile.headshot).url : "imageUrl.png"

Let us know if that doesn’t work!

1 Like

(Also, don’t forget to also update the altText!)

Hi,

Similar question, when I use the formatting above (replacing the "imageURL.png) with the name of the file I want to use, the image won’t load. I have tried this using a few different file sizes / types (jpg or png) and the results look the same every time (see screenshot attached).

Any suggestions for what might be going wrong here?

Screen Shot 2022-03-28 at 11.36.05 AM

Hi Sonia,

Make sure you’re using the full URL. This can either be a web URL or a local URL, in which case be sure it’s the full path. Here, it would not just be "imageUrl.png", but something like "static/assets/images/imageUrl.png", depending on where you saved it.

1 Like