Code templates

A code template is an outline of code that you can reuse. 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.

In the Preferences window, you can create, edit, remove, import, or export a template. 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, type a prefix and press Ctrl+Space. If the on-screen cursor is in a position where the code that is produced by the template is syntactically allowed, all of the templates whose names begin with that prefix are included in the content assist list. The templates are always at the bottom of the list for content 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 content assist. If you select one of the templates, the w is replaced by the code from the template.

Content and name considerations for code templates

The name that you give your code templates is significant because it is the keyword that represents the code template, not the first word of the code in the template. For example, assume you have created a code template named "myFunction" that consists of an EGL function that begins with thefunction keyword. 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 content assist only when you have typed at least one character to filter the list of options.

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


Feedback