<h1 th:text="${'What\'s up?'}"></h1>
I want this to output
<h1>What's up?</h1>
But I get an TemplateInputException
. I have tried with HTML entity but it fails the same.
Single quotes need to be escaped by backslash in single-quoted strings, and double quotes in double-quoted strings.
The backslash ( \ ) character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character.
A single quote is not used where there is already a quoted string. So you can overcome this issue by using a backslash following the single quote. Here the backslash and a quote are used in the “don't” word. The whole string is accompanied by the '$' sign at the start of the declaration of the variable.
Double single quote. Like this:
<h1 th:text="${'What''s up?'}" />
To escape a single quote you just escape it with a \'
<p th:text="'What\'s up?'"></p> <p th:text="${myVar} + 'What\'s up?'"></p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With