I have imageNames like wange/25011.jpg|wange/25011-1.jpg
or null, I want to split them to wange/25011.jpg
and wange/25011-1.jpg
, or no split if null. I tried code as below, but no work...
<td th:if="${brickset.imageNames} != null" th:each="image : ${#strings.arraySplit(brickset.imageNames, '|')}">
<a href="#" th:href="${imageBaseUrl + image}">
<img src="#" th:src="${imageBaseUrl + image}" height="64"/>
</a>
</td>
Thanks Linebreak are correctly displayed BUT when user type escaped character like " or ' it show \" or \' (with backslash).
Split a string at a newline character. When the literal \n represents a newline character, convert it to an actual newline using the compose function. Then use splitlines to split the string at the newline character. Create a string in which two lines of text are separated by \n .
split("-"); We can simply use a character/substring instead of an actual regular expression. Of course, there are certain special characters in regex which we need to keep in mind, and escape them in case we want their literal value. Once the string is split, the result is returned as an array of Strings.
See ${#strings. isEmpty(variable)} . It will check for empty or null and call trim() .
Here is my own answer:
<tbody id="portfolio" class="clear fix">
<tr th:each="brickset : ${bricksets}" th:alt="${brickset.description}">
<td>
<div th:unless="${brickset.imageNames == null}">
<div th:each="image,status : ${#strings.arraySplit(brickset.imageNames, '|')}">
<a href="#" th:href="${imageBaseUrl + image}" th:remove="${image} == null ? tag" th:title="${brickset.brand.name}">
<img src="#" th:src="${imageBaseUrl + image}" height="64" th:remove="${status.index} > 0 ? tag"/>
</a>
</div>
</div>
</td>
</tr>
</tbody>
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