Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New line with span loop #586

Closed
pachoyan opened this issue Mar 28, 2017 · 2 comments
Closed

New line with span loop #586

pachoyan opened this issue Mar 28, 2017 · 2 comments

Comments

@pachoyan
Copy link

pachoyan commented Mar 28, 2017

Due this question No space between elements in a Thymeleaf each loop I've done some tests.

  • Version: 2.1

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:

<span>1</span>
<span>1</span>

This is displayed by the browser with spaces due the breakline:

1 1

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:

11

But if you want an space you could be able to put it:

<span>1 </span><span>1</span>

1 1

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:

<ul>
    <li>1</li>
    <li>1</li>
</ul>


Useful info:

List of inline elements:

@danielfernandez danielfernandez self-assigned this Mar 30, 2017
@danielfernandez danielfernandez added this to the Thymeleaf 2.1 milestone Mar 30, 2017
@danielfernandez
Copy link
Member

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.

Thanks for reporting this.

@OrangeDog
Copy link

While this was "fixed", how do you get the old behaviour back (whitespace between iterated spans)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants