1

This is my code using the Thymeleaf template

<form>
     <label>
          <input type="checkbox" th:each="activeMeal : ${activeMeals}" th:text="${activeMeal.itemName}">
     </label>
</form>

This is getting generated:

enter image description here

I want each checkbox in a separate line. In a normal plain HTML I would use the <br/> tag to create the breaks. But it does not seem to be working in inside the Thymeleaf tags.

Efaz
  • 284
  • 2
  • 12
  • DON'T DO THIS, but... it is possible to use `th:utext` to avoid escaping HTML in strings. See [this question](https://stackoverflow.com/questions/23156585/process-thymeleaf-variable-as-html-code-and-not-text). I say DON'T DO THIS because of the risks. See the note in one of the answer's comments: _"...using utext makes you vulnerable to cross site scripting attacks..."_. I imagine for that reason it may be best to *never* use the `utext` approach - even if you think your specific use case may be safe. – andrewJames Apr 19 '20 at 15:34

1 Answers1

1
<th:block th:each="activeMeal : ${activeMeals}">
    <input type="checkbox" name="selectedActive" id="selectedActive" th:value="${activeMeal.itemName}"/>
    <label th:text="${activeMeal.itemName}"></label>
    <br/>
</th:block>
Efaz
  • 284
  • 2
  • 12