In a Grails taglib I have seen:
out << 'some html'
and I've also seen:
out << body() << 'some html'
What is the difference?
Thanks
The first outputs the string to the response. The second renders the body of the tag to the response and then also renders the string. Not all tags have a body, so the 2nd one is more rare. For example <g:img src='foo.gif'/>
doesn't have a body but <g:ifLoggedIn>Welcome Back</g:ifLoggedIn>
does.
When you define a tag closure, it either has one argument, typically 'attrs', or two, typically 'attrs' and 'body'. The names don't matter, they're just sensible defaults. The body
argument will be a closure that renders the inner content of the tag when it's invoked like a method (i.e. body()
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With