using

Syntax

[#using libraryQualifiedName]
or
[#using libraryQualifiedName as alias]

where:

Description

The using directive makes the macros defined in the referenced library directly available in the template.

If no alias is defined in the using directive, then each macro of the library is directly available, as if it was locally defined in the template. This is the most general and recommended usage.

There are cases where a macro may collide with another macro having the same name and defined in another used library. You can declare an alias in the using directive to resolve these conflits. The each macro call must be prefixed with the alias.

Examples

Using without alias

This library defines a currentDate macro :

[#package com.mycompany.library]

[#library CommonMacros]

[#macro currentDate]
${java.util.Calendar.getInstance().getTime().toString()}[#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/] [#-- calls 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
 */

Using with alias

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

[#package com.mycompany.example]

[#-- use an alias to resolve a macro conflict --]
[#using com.mycompany.library.CommonMacros as common]

[#-- defines locally another currentDate macro --]
[#macro currentDate]
...
[/#macro]

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