Hi there,
(sorry in advance if I don’t explain myself properly, english is not my first language)
I’m kinda a newbie on Wappler, and I have this task now:
I want to show a default image (user avatar) if there’s a ‘null’ on a DBquery that I do, but if in the field of the table that I search in there’s content (url image) then I show that output from the server action.
I do understand that the dynamic attribute does this for me, but don’t really know how to formulate the if statement in there.
I think the formatter you want to use is ‘Default’ which is in the General section of App Connect. When you set the dynamic value, add the formatter and then enter the value you’d like it to use if there isn’t one pulled in from the database.
Have a look in the browser console (right click the missing image and click ‘Inspect’) to see what is trying to be found. It’s most likely the path isn’t quite right. Could be as simple as removing the / from the beginning depending on server setup.
The issue with this is the page still tries to render the image but it's not found so you get a 404 error for that image. No problem for the user because they won't see it but the server will potentially put blocks in thinking it's being bombarded by a bot.
The server action was outputing just the file name (“fav.png”)
But I was missing the reference to the route first “/assets/img/…”
In the src binding I was just putting the result of the value, so I always (whenever I have content) just got the output “fav.png”.
Don’t know if this is the best way to fix it but my solution was to create a variable and do the ‘condition format’ in there,
And then add the value to the src:/assets/img/…
I’m pleased you have it working. Re-looking at your earlier screenshot, there are no ’ ’ around the default text so that might be why it didn’t work initially.
Do you guys might have an idea that why when the default value gets trigger and being saved in the variable; after just a second it takes again the last value from the server action?
I wouldn’t use a separate variable. Work on the original solution to get the full path into the default value and you should be fine. See my earlier post about missing quote marks.
But there’s one issue that I have with that logic.
The server action only outputs the file name to save space in the database. (image.png)
I can put the path + file name in the data format.
But I’m still missing the path for the dynamic value.
I’ll need to speak about adding the path as well in the database.
I tried that solution as well but my syntax wasn’t the right one!
Thanks!
I think it works but something else on the page is breaking this.
Apparantly, when it should show the default it does for a sec and then gets the value ‘null’ from the server action. So then shows no picture.
Guys @Teodor , @sitestreet
sorry to bother again but still can’t find a fix to a little problem that I have.
So apparently, when I have to show the user’s avatar and there’s a custom picture that must be shown; it firstly shows the default picture because it’s getting a null from the server action due to server’s action late response.
The only thing that come to my mind is to use lazy loading but still not working.
Maybe you guys could illuminate me on this.
With that I could tell that it is waiting for the server action to be executed but then it shows first the default image and the useravatar afterwards…