library

Syntax

[#library visibility libraryName]
library body
[/#library]

where:

Description

The library directive defines the name of the library, as well as the macros it contains.

The name of a library must be unique within its package, and should not collide with a text template, a ruleset or a Java type. It must match the name of the file in which it is defined: a library CommonMacros must be defined in a CommonMacros.tgm file.

Examples

This library defines a currentDate macro :

[#package com.mycompany.library]

[#library CommonMacros]

[#macro currentDate]
${java.util.Calendar.getInstance().getTime()}[#rtrim]
[/#macro]

[/#library]

It can be used in a template to print the current date:

[#package com.mycompany.example]

[#-- makes CommonMacros library's macros available --]
[#using com.mycompany.library.CommonMacros]

[#template Copyright()]
/**
 * Copyright 2006 My Company, Inc. All rights reserved.
 * [@currentDate/] [#-- call the macro currentDate --]
 */
[/#template]

The above template would produce an output similar to the following:

/**
 * Copyright 2006 My Company, Inc. All rights reserved.
 * Thu Apr 13 14:10:11 CEST 2006
 */

Related concepts
Library
Macro

Related reference
Using directive