Creating a Template and a Generated File

GTL templates are commonly used for generating files. If your template is going to be used in generation, it must be referenced in a generated file.

  1. Open your language definition or extension file in the resource editor (see Opening Resource Files in the Editor).
  2. If necessary, add a metaclass to the Profile category (see Metaclasses (Profile)) and then right-click it and select New > Template (see Templates (Profile)).
  3. Enter helloWorld as the name of the template and enter the following code in the text box:
    Hello World!
    This template is being generated for the %Name% object.
    Note: We recommend that you name your templates using headless camelCase, (starting with a lowercase letter), in order to avoid clashes with property and collection names which, by convention use full CamelCase.
  4. Right-click the metaclass again, and select New > Generated File (see Generated Files (Profile)).
  5. Enter myFile as the name of the generated file, and enter the following code in the text box to call your template:
    %helloWorld%
  6. Click OK to save your changes in the resource file and return to your model.
  7. Create an instance of the metaclass on which you defined the template and generated file, open its property sheet, and click the Preview tab.
  8. Select the myFile sub-tab to preview what would be generated for this object.