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>
Writing the <g:if> tag in a tag library
最新推荐文章于 2024-05-20 22:12:19 发布