6.3.3 逻辑标签 - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith
Version: null
6.3.3 逻辑标签
You can also create logical tags where the body of the tag is only output once a set of conditions have been met. An example of this may be a set of security tags:The tag above checks if the user is an administrator and only outputs the body content if he/she has the correct set of access privileges:
你也可以创建一个逻辑标签,一旦一组条件表达式满足,就输出标签的主体。一组安全标签的示例如下:def isAdmin = { attrs, body ->
def user = attrs.user
if (user && checkUserPrivs(user)) {
out << body()
}
}<g:isAdmin user="${myUser}"> // some restricted content </g:isAdmin>
def isAdmin = { attrs, body ->
def user = attrs.user
if (user && checkUserPrivs(user)) {
out << body()
}
}<g:isAdmin user="${myUser}"> // some restricted content </g:isAdmin>

