Tag Library Usage
A tag library fulfills role of "view helper" in the Model View Controller (MVC) pattern and helps with GSP rendering. In Grails a tag library is a class with a name that ends in the convention "TagLib" and lives in the grails-app/taglib
directory. Use the create-tag-lib command create a tag library:
grails create-tag-lib format
or with your favourite IDE or text editor.
import java.text.SimpleDateFormatclass FormatTagLib { def dateFormat = { attrs, body -> out << new SimpleDateFormat(attrs.format).format(attrs.value) } }
Each Closure property in a tag library that takes one or two arguments is considered a tag. The first argument (typically named attrs
) will contain the attributes of the tag whilst the optional second argument (typically named body
) is Closure that represents the inner HTML of the tag declaration from the GSP.
Refer to the user guide topic on Tag Libraries for more information.