我是 Grails 框架的新手,所以请记住这一点。 我有一个按钮模板,我在不同的地方渲染。我想保留模板的所有功能和除一种用途之外的所有用途的文本。
我该怎么做?
我尝试过这样的事情:
<g:render template="relativePath/myTemplate"/>
<g:message code="myLabel.newText" default="newText"/> //should replace the text in the template
显然这不起作用。
这个问题难以理解。你真的应该写出更好的问题。一般来说,如果你想向模板传递一些东西,它会是这样的:
<g:render template="relativePath/myTemplate" model="[myText: 'This is my new text']"
然后在 myTemplate 中你可以做...
<g:message ... default="${myText}"/>
然而,g:message 的重点不是硬编码消息,而是用户 messages.properties。也许您正在尝试传递不同的消息代码:...
<g:render template="relativePath/myTemplate" model="[myCode: 'myLabel.newText']"
<g:message code="${myCode}"/>