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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.