0

I'm using the following image code that will show an image only if it exists.

<img th:if="${!ad.adPhotos.empty}" th:src="|/imageDisplay?id=${ad.adPhotos[0].id}|" alt="" class="img-respocive" />

I want to show this for the else caluse

<img height="150" width="150" src="img/NoPicAvailable.png" /> 

How would this be done with Thymeleaf?

Arya
  • 8,473
  • 27
  • 105
  • 175

1 Answers1

0

I would personally do it like this:

<img th:unless="${ad.adPhotos.empty}" th:src="|/imageDisplay?id=${ad.adPhotos[0].id}|" alt="" class="img-respocive" />
<img th:if="${ad.adPhotos.empty}"height="150" width="150" src="img/NoPicAvailable.png" />

As a sidenote, I think I would generate the src with thymeleaf url syntax, rather than string concatenation.

<img th:unless="${ad.adPhotos.empty}" th:src="@{/imageDisplay(id=${ad.adPhotos[0].id})}" alt="" class="img-respocive" />
Metroids
  • 18,999
  • 4
  • 41
  • 52