2015-10-14 59 views
2

如何显示在Thymeleaf中包含HTML标签的字符串?显示在Thymeleaf模板中包含HTML的字符串

所以这段代码:

<div th:each="content : ${cmsContent}"> 
    <div class="panel-body" sec:authorize="hasRole('ROLE_ADMIN')"> 
     <div th:switch="${content.reference}"> 
      <div th:case="'home.admin'"> 
       <p th:text="${content.text}"></p> 
      </div> 
     </div> 
    </div> 

//More code.... 

并且在该行的代码${content.text}的,它确实产生该浏览器:

<p>test</p> 

但是我想表明这不是在浏览器:

test

+0

http://stackoverflow.com/questions/23156585/process-thymeleaf-variable-as-html-code-and-not-string – globalworming

回答

7

对于这种情况,您可以使用th:utext(非转义文本)。

简单地改变

<p th:text="${content.text}"></p> 

<p th:utext="${content.text}"></p> 

我会建议也看看到documentation here知道所有有关使用Thymeleaf。