Quantcast

Can't pass model from tag to template

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Can't pass model from tag to template

linus1412
Hi all,

I'm having problem passing a variable from a custom tag library to a template view:

Tag:
   
    def showBasketItem = { attrs, body ->    
        log.debug "ATTRS = ${attrs.lineItem}"        
        def journeyCode = attrs.lineItem.productType.toString().toLowerCase()
        render(template:"/${journeyCode}/basketItem", model:"[lineItem:attrs.lineItem]")
    }

log output is fine...

Template:

    <g:set var="accom" value="${lineItem.accommodation}"/>

I get a null pointer when trying to call the accommodation property on lineItem.

Any ideas?

Martin

Grails version: 1.0.2
Groovy version 1.6 beta 1
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Can't pass model from tag to template

linus1412
To answer my own question (which I seem to be getting better at)

it should have been:

  g.render template:"/${journeyCode}/basketItem", model:[lineItem:lineItem]
     
and not

  render template:"/${journeyCode}/basketItem", model:"[lineItem:lineItem]"

Notice how I'd done the ""s as you would do in a gsp.

Actually to get it to output it should have been

  out << g.render(template:"/${journeyCode}/basketItem", model:[lineItem:lineItem])
           

Lesson learned.
Loading...