简体   繁体   中英

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. 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. 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.

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. This custom gMessage can for example by Convention looking for properties prefixed by a model parameter. Than in the render of the gsp you can only set the prefix string in the model.

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

In your template 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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