2013-10-18 27 views
1

我有一个grails呈现标记,它呈现一小块HTML。有时,HTMl需要显示一些文本,有时候会显示一些文本和链接。将链接作为参数传递给g:在grails中呈现标记

这个代码块是工作的罚款:

   <g:render template='accountInfo' model="[ 
         'accountStatus':subscription.status, 
         'subscription':subscription.plan.name, 
         'msg':g.message (code: 'stripe.plan.info', args:'${[periodStatus, endDate]}')]"/> 

但我希望能够在某些HTML以通为“味精”变量模型,这样对输出中的一些文字和链接:

   <g:render template='accountInfo' model="[ 
         'accountStatus':profile.profileState, 
         'subscription':'None selected yet', 
         'msg':<a href="${createLink(controller: 'charge', action: 'basicPlanList')}" title="Start your Subscription">Your profile is currently inactive, select a plan now to publish your profile.</a>]"/> 

该代码不起作用。我尝试添加的链接标签库,但我无法弄清楚如何的taglib传递给“味精”之一:

   <g:render template='accountInfo' model="[ 
         'accountStatus':profile.profileState, 
         'subscription':'None selected yet', 
         'msg':<abc:showThatLink/>]"/> 

我愿意接受建议,就如何更好地实现传递文本只有文本和grails createLink封闭以及链接的一些文本。

回答

3

你有多种选择:

1使用引号:

<g:render template='accountInfo' model='${ [msg: "<a href='www.someurl.com'>.. </a>"]}' /> 

2使用另一个变量:

<g:set var="myMsg> 
    <a href="www.someurl.com>...</a> 
</g:set>` 
<g:render template='accountInfo' model='[ 'msg': ${myMsg} ]'/> 

3使用的<g:render />的主体内容:

<g:render template="accountInfo" model="[ .. ]"> 
    <a href="..">..</a> 
</g:render> 

您可以使用模板内的body()方法(accountInfo)来呈现正文内容。前段时间,我写了一个small blog post about this,它提供了更多的细节。

+0

#2工作,但我不得不删除封闭的味精让它运行:'味精':myMsg – spock99

相关问题