Extending a template from a class

Gosu provides a special syntax to simplify calling static methods on a class. The metaphor for this template shortcut is that your template can extend from a type that you define. Technically, templates are not instantiated as objects. However, your template can call static methods on the specified class without fully qualifying the class. Static methods are methods defined directly on a class, rather than on instances of the class.

To use this feature, at the top of the template file, add a line with the following syntax:

<%@ extends CLASSNAME %>

CLASSNAME must be a fully qualified class name. You cannot use a package name or hierarchy.

You can use the extends syntax in template files, but not in String literals that use template syntax.

Example

Suppose your template needs to clean up the email address with the sanitizeEmailAddress static method on the class gw.api.email.EmailTemplate. The following template takes one argument that is an email address:

<%@ params(address : String) %>
<%@ extends gw.api.email.mailTemplate %>
Hello! The email address is ${sanitizeEmailAddress(address)}

Notice that the class name does not appear immediately before the call to the static method.

See also