2013-10-18 32 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

相關問題