简体   繁体   English

Grails渲染标记和message.properties

[英]Grails render tag and message.properties

I am using the g:render grails tag to avoid to repeat common part of HTML in my app to be repeated. 我正在使用g:render grails标记来避免在应用程序中重复HTML的常见部分。 Now I need in some of them to pass some properties, such as the title of the sections, through the message.properties file so those can be translated. 现在,我需要在其中一些属性中通过message.properties文件传递某些属性(例如,各节的标题),以便可以进行翻译。 To make it work I'm using this structure: 为了使其正常工作,我使用以下结构:

 <g:set var="title" value="${g.message (code: 'completed.thanks')}" />
 <g:render template="thankYou" contextPath="/completed/" model="[title:title,other:other]" />

but I was wondering if there is any better solution to provide the string in the model of the render tag itself. 但是我想知道是否有更好的解决方案在render标签本身的模型中提供字符串。

if properties passed are many this approach can not be the best. 如果传递的属性很多,则此方法可能不是最佳方法。 In that case I suggest to reate a custo implementation of g:message using a customTaglib. 在那种情况下,我建议使用customTaglib来实现g:message的custo实现。 This custom gMessage can for example by Convention looking for properties prefixed by a model parameter. 该自定义gMessage可以(例如)通过Convention查找以模型参数为前缀的属性。 Than in the render of the gsp you can only set the prefix string in the model. 比起gsp的渲染,您只能在模型中设置前缀字符串。

 <g:render template="thankYou" contextPath="/completed/" model="[prefix: 'pagex']" />

In your template gsp: 在您的模板gsp中:

...
<custom:message code="completed.thanks" prefix="${prefix}"/>
<custom:message code="completed.byebye" prefix="${prefix}"/>
...

In properties file 在属性文件中

pagex.thanks=bla bla bla
pagex.byebye=bla bla bla
pagey.thanks=bla bla bla
pagey.byebye=bla bla bla

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM