Search code examples
spring-mvcthymeleaf

Why image source get unknown?


In this below code if condition is true then work well but if condition is false looking weird image src...

Here down my code

<img th:src="${(profileData.profile != null) ? profileData.profile : '../images/users/app-store.png'}" alt="" class="img-responsive profile-photo" />

Inspect

<img src(unknown) alt="" class="img-responsive profile-photo">

Output

enter image description here

Expected

enter image description here


Solution

  • According to https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#conditional-expressions

    <img th:src="${(profileData.profile != null)} ? ${profileData.profile} : '../images/users/app-store.png'" alt="" class="img-responsive profile-photo" />
    

    Hint: check your closing bracket } in your initial condition