Search code examples
thymeleaf

Nested tag with text and variable are not interpreted


I have nested tag

today is not interpreted

<p th:text="#{today}">  <span th:text="${today}">16 december 2021</span> </p>

With this line, that work but that don't get the same output

<p th:text="#{today}"> </p> <span th:text="${today}">16 december 2021</span>

Solution

  • <p>
      [[#{today}]]
      <span th:text="${today}">16 december 2021</span>
    </p>
    

    or

    <p>
      <span th:text="#{today}" />
      <span th:text="${today}">16 december 2021</span>
    </p>
    

    Outer tags overwrite their contents, so just move the outer text in.