spock99
spock99

Reputation: 1184

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

I have a grails render tag that renders a small chunk of HTML. Sometimes the HTMl needs to display some text, and sometimes some text and a link.

This chunk of code is working fine:

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

But I want to be able to pass in some HTML for the 'msg' variable in the model, like this to ouput some text and a link:

                <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>]"/>

That code does not work. I've tried adding the link to a taglib, but I can't figure out how to pass the taglib to the 'msg' either:

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

I am open to suggestions on how best to achieve passing in text only, and text and a grails createLink closure along with some text for the link.

Upvotes: 1

Views: 1360

Answers (1)

micha
micha

Reputation: 49572

You have multiple options:

1 Use quotes:

<g:render template='accountInfo' model='${ [msg: "<a href='www.someurl.com'>.. </a>"]}' />

2 Use another variable:

<g:set var="myMsg>
  <a href="www.someurl.com>...</a>
</g:set>`
<g:render template='accountInfo' model='[ 'msg': ${myMsg} ]'/>

3 Use the body content of <g:render />:

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

You can use to body() method inside the template (accountInfo) to render the body content. Some time ago I wrote a small blog post about this which gives some more details.

Upvotes: 3

Related Questions