[#template visibility templateName(parameters)]
    template body


Each parameter is of the form:

direction name : type



The template directive defines the signature of a text template, as well as the contents to be generated.

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

The template may define expected parameters, used to compute the generated contents. Any caller of the template must provide matching arguments. A template is usually used to produce a text output based on model elements that won't be modified during the generation. So most of the time, the direction in will be used to define a model parameter, although you're free to use out and inout.

The contents generated is the result of the evaluation of the template body. Any character outside of the template tags (for example the lines between the package declaration and the template start tag) will not be part of the output.

The template contents usually starts with a file directive, which defines the name of the file where the generated text will be written. If you don't use a file directive, then the template is designed to be included inside another template.


This will generate a simple Java source file based on a UML 2.1 Class:

[#package com.mycompany.example]

[#template GenerateJavaClass(class : uml21.Class)]
public class ${class.name} {

This will generate a text file based on a UML 2.1 model, where the generation is configured using a boolean value:

[#package com.mycompany.example]

[#template GenerateText(in model : uml21, simpleMode : boolean)]
some text to generate using this boolean value: ${simpleMode}

Related concepts
Text template