I'am using Thymeleaf in combination with a js micro-templating routine, which result in special characters in attribute values. When running Thymeleaf on
<a style="display:<%= x ? 'block' : 'none' %>;">
it creates
<a style="display:<%= x ? 'block' : 'none' %>;">
while I would expect to get exactly the same I put into the processor. How do I use special characters in HTML attribute values? Many thanks!
Try to play with
th:utext="#{unescaped text}">
See Thymeleaf doc Unescaped Text
There is some variants to review:
LEGACYHTML5
option in templateResolver
as mentioned abovetemplate
method in Underscore.jsI prefer second approach. Place this code in your initialization script:
var original = _.template;
_.template = function(content) {
// fix operators escaped by Thymeleaf HTML5 validator
content = content.replace(/'/g, "'");
content = content.replace(/</g, "<");
content = content.replace(/>/g, ">");
return original.call(this, content);
};
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