////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////


=== 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 link:{commandLineRefFromRef}create-taglib.html[create-taglib] command to create a tag library:

[source,groovy]
----
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

[source,groovy]
----
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 link:{guidePath}theWebLayer.html#taglibs[Tag Libraries] for more information.
