【问题标题】:Pass a link as a paremeter to g:render tag in grails将链接作为参数传递给 grails 中的 g:render 标签
【发布时间】:2013-10-18 19:55:10
【问题描述】:

我有一个 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 闭包以及链接的一些文本的建议。

【问题讨论】:

    标签: grails gsp


    【解决方案1】:

    您有多种选择:

    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 使用&lt;g:render /&gt;的正文内容:

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

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

    【讨论】:

    • #2 有效,但我必须删除 msg 的闭包才能使其运行:'msg':myMsg
    猜你喜欢
    • 2019-02-03
    • 2020-11-08
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多