0

Using thymeleaf in spring boot project. Got a template with long texts and was wondering if it is possible to interpolate variables without using a tag. For example, instead of:

<div th:if="${someCondition}" th:remove="tag">
Foo bar long text <span th:text="${someVariable}" th:remove="tag"/>,lorem ipsum <span th:text="${anotherVariable}" th:remove="tag"/>
<span th:text="${thirdVariable}" th:remove="tag" />.
</div>

Something similar to this (e.g.: handlebars):

<div th:if="${someCondition}" th:remove="tag">
Foo bar long text {{someVariable}}, lorem ipsum {{anotherVariable}} {{thirdVariable}}.
</div>

The latter I found a lot easier to read and work with.

naimdjon
  • 3,162
  • 1
  • 20
  • 41

1 Answers1

3

You can do this with expression inlining.

<div th:if="${someCondition}" th:remove="tag">
  Foo bar long text [[${someVariable}]], lorem ipsum [[${anotherVariable}]] [[${thirdVariable}]].
</div>
Metroids
  • 18,999
  • 4
  • 41
  • 52