Don't avoid th: content tag in Thymeleaf

I am currently working on a Spring Boot project with Thymleaf 2.1.3. I am adding some meta tags to the page by doing:

<meta name="pagename" th:content="${pagename}"/>

The pagename variable is populated by the controller. This works, but due to the pagename being HTML escaped. This is not the correct behavior for my application. I sanitize the data myself, after which it should be put in the content of the content tag.

I looked around and found th: inline which doesn't work for content tags. Also found th: utext, but that also doesn't work for th: content ..

Does anyone know a solution to this problem?

Thank!

+3


source to share


1 answer


As far as I know, Thymeleaf always avoids content going into HTML attributes as per the XML / HTML specification which dictates that content should be escaped. However, there may be a couple of workarounds discussed on the forum by others trying to do the same: http://forum.thymeleaf.org/How-to-get-unescaped-text-into-title-attribute-td4027791. html

One involves building your own attribute processor, the other involving syntax cracking.



Do I need to sanitize the content myself first? Can you prevent Thymeleaf from doing this at the presentation level?

0


source







All Articles