I am new in spring thymeleaf and I am not able to get difference between these two data-th-text
and th:text
.
Can anyone explain the difference, with the help of examples, and when should I use data-th-text
and th:text
?
Both does the same thing but as per thymeleaf docs:
Non-standard attributes we are using in the
th:*
form are not allowed by the HTML5 specification. To make your templates HTML5-valid usedata-
prefix for attribute names andhyphen (-)
separators instead ofsemi-colons (:)
Ref: https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#using-texts
This is not HTML5 valid:
<p th:text="#{home.welcome}">Welcome to our grocery store!</p>
This is HTML5 valid:
<p data-th-text="#{home.welcome}">Welcome to our grocery store!</p>