"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.4/grails-docs/src/test/resources/docs/ref/Tag Libraries/Usage.html" (14 Sep 2022, 59653 Bytes) of package /linux/www/grails-core-5.2.4.tar.gz:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the grails-core-5.2.4.tar.gz project site itself.

(Quick Reference)

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-taglib command to create a tag library:

grails create-taglib format

or with your favourite IDE or text editor make a new file with the name FormatTagLib in grails-app/taglib as given below

import java.text.SimpleDateFormat

class 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.