If condition fails

Hi All
I have a collection one item in the list is an Image and if the image object in the collection is null it should show a static picture and if image is available then show it from original. I’ve learned that if condition is a function and therefore I will get “Cannot read properties of null (reading ‘url’)”.
But How can I do it with real if else statement?

if(context.item.data[‘image’]==null,“https://xxxxxxxxxx/vault//trainer_man_people_avatar_person_icon_224822.png”,context.item.data[‘image’][‘url’])

The error message you provided states that the object context.item.data[‘image’][‘url’] is null, but your condition is on context.item.data[‘image’]. Have you confirmed that the latter is null as well?

You might want to check for =="undefined" and =="" too (although probably not the issue here).

Also, it seems you’re getting this data from the page context, not a collection directly. Is this expected? context.item.[...] is pointing to the page context, not a collection if I’m not mistaken.



It is a collection and I’ll define the rule for the second element that’s a image. if item.data[‘image’] is null then I would like to show a static image

Switch to “javascript” mode so you can use a if/else statement.
image

4 Likes

OMG!!! That’s perfekt!! I try to enter Javascript into the formula editor :slight_smile:
Most of the things in WeWeb are intuitiv and I could figure it out by myself!
I love WeWeb and the awesome support!!!

TX so much it is working

2 Likes

Maybe you could also try to reverse the condition :
If (item.date['image'], item.date['image']['url'], “...trainer_man_people_avatar_person_icon_224822.png”)

2 Likes