我有一个 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>
您可以使用
body()
模板( accountInfo
)内的方法来呈现正文内容。前段时间我写了一个small blog post about this这提供了更多细节。
关于grails - 将链接作为参数传递给 g :render tag in grails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19457988/