Merušić
Merušić

Reputation: 138

How can i go to next line inside the th:text in Thymleaf?

I m encountering a problem with the '\n' or
in thymleaf the problem is i need to enter to a new line. I have iteretate inside the inside of cell. I m getting the content but just in one line and i want one tweet under the other inside the cell. and i saw as well some similiar topic but it is not working in my case.

This is what i m getting:

enter image description here

How should i manage it to go in the next line inside one cell.

The Thymleaf code:

 <tr>

<td th:text="${user.id}">1</td>
<td th:text="${user.getUsername()}">Hamdo</td>
<span th:each="tweet : ${tweets}">
<td th:text="${tweet.content} " ><br/>
 <br/>
</td>
</span>

The controller :

@GetMapping({"", "/", "/index", "/index.html"})
public String  followers(Principal principal, Model model) {
User user=userService.getUser(principal.getName());
model.addAttribute("tweets",
tweetService.tweetsFromUser(principal.getName()));
 model.addAttribute("user",user);
 return "index";
}

The service class:

 private List<TweetDTO> tweetsFromUser(User user) {
return tweetRepository.findAllByAuthor(user).stream().map(TweetDTO::new).collect(toList());
}

Upvotes: 1

Views: 73

Answers (1)

Metroids
Metroids

Reputation: 20477

You don't need the extra span... just loop inside of the <td />, like this:

<tr>
  <td th:text="${user.id}">1</td>
  <td th:text="${user.username}">Hamdo</td>
  <td>
    <p th:each="tweet : ${tweets}" th:text="${tweet.content}" />
  </td>
</tr>

Upvotes: 1

Related Questions