Prev Next

Create Custom Templates

Enterprise Architect provides a wide range of templates that define how code elements are generated. If these are not sufficient for your purposes - for example, if you want to generate code in a language not currently supported by Enterprise Architect - you can create completely new custom templates. You can also add stereotype overrides to your custom templates; for example, you might list all of your parameters and their notes in your method notes.

Access

Ribbon

Code > Configure > Options > Edit Code Templates

Design > Tools > Transform > Transform Templates

Keyboard Shortcuts

Ctrl+Shift+P (code generation templates)

Ctrl+Alt+H (MDA transformation templates)

Create custom templates using the Code Templates Editor

Step

Description

See also

1

In the 'Language' field, click on the drop-down arrow and select the appropriate programming language.

2

Click on the Add New Custom Template button.

The 'Create New Custom Template' dialog displays.

3

In the 'Template Type' field, click on the drop-down arrow and select the appropriate modeling object.

The '<None>' option requires special treatment; it enables the definition of a function macro that doesn't actually apply to any of the types, but must be called as a function to define variables $parameter1, $parameter2 and so on for each value passed in.

4

In the 'Template Name' field, type an appropriate name.

Click on the OK button.

5

On the 'Code Templates Editor' tab, the new template is included in the 'Templates' list, with the value 'Yes' in the 'Modified' field.

The template is called <Template Type>__<Template Name>.

Note the double underscore character between the template type and template name.

6

Select the template from the Templates list and edit the contents in the Template field to meet your requirements.

Code Template Syntax

7

Click on the Save button.

This stores the new template, which is now available from the list of templates for use. You can also add a stereotype override to the template, if necessary.

Add New Stereotyped Templates

Notes

  • For a custom language, you must define the File template so that it can call the Import Section, Namespace and Class templates, and any other templates that you decide are applicable

Learn more