Process thymeleaf variable as html code and not text

前端 未结 2 1195
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-01 13:46

I\'m using Thymeleaf to process html templates, I understood how to append inline strings from my controller, but now I want to append a fragment of html code into the page.

相关标签:
2条回答
  • 2020-12-01 14:00

    If you want short-hand syntax you can use following:

    [(${variable})]
    

    Escaped short-hand syntax is

    [[${variable}]]
    

    but if you change inner square brackets [ with regular ( ones HTML is not escaped.

    Example within tags:

    <div>
        [(${variable})]
    </div>
    
    0 讨论(0)
  • 2020-12-01 14:11

    You can use th:utext attribute that stands for unescaped text (see documentation). Use this with caution and avoid user input in th:utext as it can cause security problems.

    <div th:remove="tag" th:utext="${n}"></div>
    
    0 讨论(0)
提交回复
热议问题