I came across a groovy syntax that creates a link in gsp file like this:
class LoginTagLib {
def loginControl = {
out << """[${link(action:"login",controller:"user"){"Login"}}]"""
}}
I know that it will eventually turned into this in html:
<a href="/racetrack/user/login">Login</a>
However, there are 2 portion of the syntax that I don’t understand:
-
I don’t understand
${link(action:"login",controller:"user"){"Login"}}:- I get the
$(), which is used for string interpolation. - I get the
link(action:"login",controller:"user")too, just 2 arguments passed intolink - but what is the
{"Login"}doing behind?
- I get the
-
I don’t understand the
"""[ ]"""that is used to enclose the whole thing, I tried to take away a pair of", but it wounldn’t work anymore. So it proves to me it has it’s significance.
Anybody help to shed some light?
Thanks
foo(arg1, arg2, ..., { ... })tofoo(arg1, arg2, ...) { ... }. this is what happens here, the last argument oflink()is a closure that should evaluate to the textual representation of the link