Using << in Grails taglib

In taglib Grails, I saw:

 out << 'some html' 

and I also saw:

 out << body() << 'some html' 

What is the difference?

thanks

+6
source share
1 answer

The first prints a line to the answer. The second displays the body of the tag on the response, and then displays the string. Not all tags have a body, so the second is less common. For example, <g:img src='foo.gif'/> does not have a body, but <g:ifLoggedIn>Welcome Back</g:ifLoggedIn> does.

When you define the closing of a tag, it either has one argument, usually "attrs" or two, usually "attrs" and "body". Names do not matter, they are just reasonable defaults. The body argument will be a closure that displays the internal content of the tag when called as a method (i.e. body() )

+17
source

Source: https://habr.com/ru/post/894904/


All Articles