I want to show the user avatar if it exists and show a default avatar if not. The code I use is:
<img src="/images/commentavatar1.png" th:src="${comment.user.image} != null ? ${comment.user.image} : '/images/default-user.png'" th:alt="${comment.user.nameSurname}"/>
What I see is only the alt tag. The rendered element has an empty src attribute. Thank you.
try
<img th:src="${(comment.user.image != null && !#strings.isEmpty(comment.user.image)) ? comment.user.image : '/images/default-user.png'}" th:alt="${comment.user.nameSurname}"/>
try.. change &&
to AND
<img th:src="${(comment.user.image != null && !#strings.isEmpty(comment.user.image)) ? comment.user.image : '/images/default-user.png'}" th:alt="${comment.user.nameSurname}"/>
to
<img th:src="${(comment.user.image != null AND !#strings.isEmpty(comment.user.image)) ? comment.user.image : '/images/default-user.png'}" th:alt="${comment.user.nameSurname}"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With