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    Tools | Source Code Generation Templates ( Ctrl+Shift+P )

Create custom templates using the Code Templates Editor



See also


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




Click on the Add New Custom Template button.

The Create New Custom Template dialog displays.




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.




In the Template Name field, type an appropriate name.

Click on the OK button.




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.




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


Code Template Syntax


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 you wish.


Add New Stereotyped Templates


·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