Search code examples
springspring-bootescapingthymeleaf

How to use escaped colon in thymeleaf th:text?


This is what happens when I try to use a colon in th:text:

enter image description here

and a backslash doesn't seem to fix it:

enter image description here

How can I use the colon symbol in th:text?


Solution

  • If you want to place a literal into th:text, you have to use single quotes: th:text="'7:00AM'". See documentation here.

    (By contrast, something like this th:text="7_00AM" is valid - because it is a literal token. Such strings can only use a subset of characters, but do not need enclosing 's.)