Grails 如何将字符串bean中的html标记作为g:render标记的模型传递
我有一个模板,我需要将动态文本作为字符串传递给它。一些字符串具有html标记。当我使用html标记时,会出现错误。你知道怎么解决这个问题吗Grails 如何将字符串bean中的html标记作为g:render标记的模型传递,grails,groovy,Grails,Groovy,我有一个模板,我需要将动态文本作为字符串传递给它。一些字符串具有html标记。当我使用html标记时,会出现错误。你知道怎么解决这个问题吗 <g:render template="/modals/note" model="['copy':'<b>Note:</b> bla bla price is ${bean.dueAmount}']"/> 使用JSTL(Java标准标记库)首先设置值。比如: <%@ taglib prefix="c" uri=
<g:render template="/modals/note" model="['copy':'<b>Note:</b> bla bla price is ${bean.dueAmount}']"/>
使用JSTL(Java标准标记库)首先设置值。比如:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="note">
<%-- Escape markup using c:out --%>
<c:out escapeXml="false">
<b>Note:</b> bla bla price is ${bean.dueAmount}
</c:out>
</c:set>
注:bla bla价格为${bean.dueMount}
然后使用它:
<g:render template="/modals/note" model="['copy':${note}]"/>
我在本地工作: 母公司普惠制
<g:set var="note">
<b>Note:</b> bla bla price is ${bean.dueAmount}
</g:set>
<g:render template="/modals/note" model="[copy: note]" />
注:bla bla价格为${bean.dueMount}
模板普惠制
<div id="note-module" class="modal fade hide">
<div class="modal-body">
<p>${copy}</p>
</div>
</div>
${copy}
我能够删除原始/无编码,因为
note
是在g:set
正文中设置的。谢谢Brian,但是使用model=“['copy':${note}]会导致错误。通过删除${}.model=“['copy':note]”使其正常工作,但唯一的问题是它将note处理为一个字符串,所以当它呈现时看起来像这样注意:bla-bla-price是1.00“@ericb我更新了我的答案以转义xml-我想可能是模板在这么做。当然-我的解决方案使用JSTL标记是冗长的-必须有一个grails本地等价物,但这会起作用。在我的_Note.gsp中,我只有一个名为${copy}的变量因此,我不确定您的示例所指的是什么。我尝试将${raw(copy)}包装到gsp的{u note.gsp中,但仍然会出现相同的错误。您的{u note.gsp看起来像什么?${copy}我根据您的反馈进行了更改。谢谢tylerwal。问题是,即使我使用了g:set变量,我在尝试传递任何html标记时也会出错。如果我删除了任何html标记,那么您的示例一切都很好。我仍然需要能够传递html标记