Reputation: 1020
<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.
Upvotes: 26
Views: 24123
Reputation: 1
To display Oct'24
th:text="${#temporals.format(billSummary.billYearMonth,'MMM''yy')}"
Upvotes: 0
Reputation: 51
if you want transfer code such as onclick="showName('John')" to thymeleaf expression, use th:onclick=(${'showName'(\''+name+'\''}) that will get error:EL1065E: Unexpected escape character. And then,use double sigle quote to fix:
is this right?
<div th:onclick="${'showName('''+name+''''}"></div>
do test,WTF! double single quote is escaped to ''';。after some research,i found the corret way is:
correct now:
<div th:onclick="'showName(\''+${name}+'\''"></div>
you should keep ${name} as whole,as an atomic,don't use '+' operation in it.
i think only th:onclick just like that,th:text can use add operation in it.
My English is funny,but i think you can understand.
Upvotes: 0
Reputation: 11367
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>
Upvotes: 10
Reputation: 20477
Double single quote. Like this:
<h1 th:text="${'What''s up?'}" />
Upvotes: 43
Reputation: 443
maybe use htm ascii code : '
<h1 th:text="${'What's up?'}"></h1>
Upvotes: 3