(Quick Reference)

Tag Library Usage

A tag library fulfills role of "view helper" in the Model View Controller (MVC) pattern and is responsible aiding GSP rendering. In Grails a tag library is a class that ends in the convention "TagLib" and lives in the grails-app/taglib directory. A controller can be created with the create-tag-lib command:

grails create-tag-lib format

Or via your favourite IDE or text editor.

class FormatTagLib {
    def dateFormat = { attrs, body ->
        out << new java.text.SimpleDateFormat(attrs.format).format(attrs.value)
    }
}

Each property in a tag library that takes two arguments is considered a tag. The first argument attrs is the attributes of the tag whilst the second body argument is another block or closure that can be invoked.

Refer to the user guide topic on Tag Libraries for more information.