# Using Templates

Templates are shortcuts used to insert a pre-defined framework of code into your scripts. The purpose is to save time and reduce the potential for errors in standard, repetitive code units. Once a template is inserted, you can complete the code quickly using manual and automated code entry methods.

Requirements:

A template must be defined in the Templates list in the Template Preferences page, accessed from Window | Preferences | PHP | Editor | Templates, before it can be used. To learn how to create a new template from the Templates Preferences page, see Adding a New Template.Templates are context sensitive and can be used in HTML, PHP, PHPDOC, JavaScript or CSS. The context of the current code being entered defines which templates are available. For example, PHP templates are not available if your current code is Java.

### Inserting a Template into Code

This procedure describes how to insert a template into your script.

To insert a template:

1. Place your cursor at the desired insertion point.
2. Enter a character string (e.g. "Sw").
3. Click Ctrl+Space. The Content Assist box will appear, listing all available templates and completion options that begin with that combination of keys. Templates are marked in the content assist list with a blue square.
4. Double-click the required template from the list. The template will be entered into your code.

#### Example:

Entering "sw" and selecting the "switch statement" template from the list will give you the following code:

#### Note:

Templates can be created, imported and exported through the Template Preferences page, accessed from Window | Preferences | PHP | Editor | Templates.

#### Related Links:

- Templates Preferences
- Using Content Assist