How to escape single quote (') in Thymeleaf

b2238488 picture b2238488 · Mar 30, 2017 · Viewed 12.1k times · Source

<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.

Answer

Metroids picture Metroids · Mar 30, 2017

Double single quote. Like this:

<h1 th:text="${'What''s up?'}" />