Using Templates

Templates are shortcuts used to insert a framework for a new section of code. This section may be anything (e.g., the framework for a Do statement, class construction, while, etc.). The purpose is to save time and reduce the potential for errors in standard repetitive code units. Once a template is inserted, you can write code quickly using both manual and automated code entry methods.

Requirements:

* A template must be defined in the Templates list in order for the shortcut to work (Windows | Preferences | Templates).

* Templates are context sensitive: HTML, PHP, PHPDOC, JavaScript or CSS. This context of the current code defines which templates work and which do not.

Defining Templates

1. Click Windows | Preferences | Templates.

The Templates dialog opens.

              Figure: 1 -  Templates

2. Press New. The New Template dialog opens.

              Figure: 2 -  New Template

3. Enter the template’s details:

a. Name – a short name to identify the template (e.g. a template for a while loop may be called while).

b. Context – The template’s code context (PHP, PHPDoc, HTML).

c. Description – A short description of the template’s code.

d. Pattern – The actual code to be inserted into the editor when selecting the template.

e. Insert Variable – Displays a list of commonly used variables. You may add one (or more) to the template.

              Figure: 3 -  Insert Variable

4. Click OK to save the new template or Cancel to exit without saving.

              Figure: 4 -  New Template Added to Template List

To insert a template into your code:

1. Place your cursor at the desired insertion point.

2. Enter a character string (e.g. “Sw”). Click CTRL+SPACE. A completion list opens (PHP only) listing all available templates and completion options that begin with that combination of keys.

              Figure: 5 -  Inserting template into code

3. Templates are marked in the code completion list with a blue

square, select a template from the list, or double click.

4. You can now navigate from variable to variable within the code added to file.