I want to put double quotes in a String in Thymeleaf, I have something of the form:
<td th:text='${"Value of \"" + item + "\" is \"" + value + "\"."}'></td>
The result i want is:
<td>Value of "apple" is "1.5".</td>
But I get the following exception:
EL1065E: unexpected escape character.
How can I do this?
“Double quotes 'escape' double quotes“ When using double quotes "" to create a string literal, the double quote character needs to be escaped using a backslash: \" .
key}" + 'what\'s up' " context.
2. How to Escape Quotes in a String. To add quoted strings inside of strings, you need to escape the quotation marks. This happens by placing a backslash ( \ ) before the escaped character.
I'm not sure it's possible. Something like this works:
th:text='|Value of "${item}" is "${value}".|'
I would personally write it like this:
th:text="${'Value of "' + item + '" is "' + value + '".'}"
I think the reason there is no way to escape double quotes, is that thymeleaf is first parsing as xml/html (which has no escape other than "
) and then parsing as thymeleaf second which doesn't really have a chance to get at those strings.
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