Writing the tag in a tag library

The internal if/else tags that come with Grails translate directly
into if(..) {} else {} at the syntax level to improve performance of
such core tags . But you can quite easily write if/else tags using the
pageScope object and Grails' standard tags

for example:

def ifSomething = { attrs, body ->
     pageScope.doElse = !attrs.condition
     if(attrs.condition) out << body()
}
def elseSomething = { attrs, body ->
    if(pageScope.doElse)  out << body()
}

Then

<g:ifSomething condition="${1==2}">yes</g:ifSomething>
<g:elseSomething>no</g:elseSomething>

你可能感兴趣的:(grails,performance)