繁体   English   中英

将链接作为paremeter传递给grails中的g:render标记

[英]Pass a link as a paremeter to g:render tag in grails

我有一个grails渲染标记,可以呈现一小部分HTML。 有时HTMl需要显示一些文本,有时还需要一些文本和链接。

这段代码工作正常:

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

但是我希望能够为模型中的'msg'变量传递一些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,但我无法弄清楚如何将taglib传递给'msg':

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

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

您有多种选择:

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>

您可以使用模板( accountInfo )中的body()方法来呈现正文内容。 前段时间我写了一篇关于此小博文 ,其中提供了更多细节。

暂无
暂无

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

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