You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Thymeleaf 3.0, a th:each will work in the way you detail when added to a <span> tag.
Spacing around iterated elements is actually a quite complex feature in the Thymeleaf engine, much more complex than it can probably seem to be (esp. in 3.0 where iteration is engineered deep into the template engine core itself in order to improve streaming performance for large iterations).
Despite the complexity, in v3.0 there was a possibility to make the behaviour of this iteration spacing dependent on the specific tag being used, and we did it (so <span> does not add line feeds whereas <td> or <li> do); but this would not be an easy task in 2.1's engine, which is completely different in this regard. Now that 3.0 is almost one year old, I honestly see no reason to add this kind of complexity to the old 2.1 engine.
Due this question No space between elements in a Thymeleaf each loop I've done some tests.
So if you want to use a loop using a
<span>
tag, for example, just like the question:<span th:each="item : ${X}">1</span>
You'll get the with breaklines. It would be next output:
This is displayed by the browser with spaces due the breakline:
But, you cannot choose if you want an space or not. It will be displayed due the breakline.
For example:
<span>1</span><span>1</span>
Will be displayed:
But if you want an space you could be able to put it:
<span>1 </span><span>1</span>
So, IMHO I think you would be able to choose if you want this space or not:
For example:
If you want the space you'll write:
<span th:each="item : ${X}">1 </span>
And thymeleaf will process
<span>1 </span><span>1 </span>
But instead if you want to use it without spaces:
<span th:each="item : ${X}">1</span>
Thymeleaf will process
<span>1</span><span>1</span>
So, It could be better in the case of inline tags thymeleaf process they without a new line.
Otherwise, with other tags this behavior is the best option to improve readability as it does (#113). For example a list:
Useful info:
List of inline elements:
The text was updated successfully, but these errors were encountered: