grails - 将链接作为参数传递给 g :render tag in grails

标签 grails gsp

我有一个 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/

相关文章:

Grails 缓存 ehcache 插件和 TTL 值

grails - 在特定操作后保留排序 - Grails

grails - 如何为 grails 2.4.4 配置 javamelody?获取 "Bad artifact coordinates"!

jquery - 在Grails 2.2.3和2.3.11之间更改JSON/XML默认响应格式

grails - 如何在 GSP 页面中递归列出 child ?

grails - Grails时间持续时间格式标记库

grails - Grails yui-minify-resources和lesscss-resources冲突

grails - Grails 3 Bootstrap -服务不会创建数据库条目

grails - 如何在Grails中的gsp上根据环境在Config.groovy中设置值并获得相同参数的不同值?

grails groovyPageRenderer 注入(inject) src/groovy 中的文件