(Quick Reference)

6.3.3 Logical Tags - Reference Documentation

Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith

Version: null

6.3.3 Logical Tags

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:

Puede tambien crear etiquetas logicas donde el cuerpo de la etiqueta es solo salida una vez que un conjunto de condiciones hallan sido cumplidas. Un ejemplo de esto pueden ser un conjunto de etiquetas de seguridad:

def isAdmin = { attrs, body ->
    def user = attrs.user
    if (user && checkUserPrivs(user)) {
        out << body()
    }
}

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:

La etiqueta de arriba checa si el usario es un administrador y solo muestra el contenido del cuerpo si el/ella tiene el conjunto correcto de privilegios de acceso:

<g:isAdmin user="${myUser}">
    // some restricted content
</g:isAdmin>