Code templates

A code template is an outline of code that can be reused. Typically, templates are used for functions that are routine, such as retrieving data from a data source. To use a template, that template must be enabled in the code template preferences.

You can create, edit, remove, import, or export a template by using the Preferences window. If you have modified the list of default templates, you can restore the list to its default value. You can also restore a removed template if you have not exited from the workbench since it was removed.

To see the templates, you must type a prefix and then press Ctrl+Space. All templates whose name begins with that prefix are included in the code assist list, provided the on-screen cursor is in a position where the code produced by the template is syntactically allowed. The templates are always at the bottom of the list for code assist. For example, if the cursor is position in a place where a function is permitted, and you type w, the webservice_function templates are listed in code assist. If you select one of the templates, the w is replaced by the code from the template.

Content and naming considerations for code templates

The that name you give your code templates is significant because that name is the keyword that represents the code template, not the first word of the code in the template itself. For example, assume you have created a code template named "myFunction" that consists of an EGL function, beginning with the keyword function. When you want to insert this template, you must begin by typing letters from the name, such as my or myFunc, not f or fun. Templates are displayed in code assist only when you have typed at least one character to filter the list of options.

Also, if you begin the code template with an EGL keyword such as function, the template will be available only when the cursor is in a place where that keyword is valid. In this case, the function template would be an option only if the cursor is in a place where a function would be valid. If the beginning of the template is not an EGL keyword, the template can be inserted anywhere.