Creating and Using Code Templates

From Delphi for PHP Documentation Wiki

Jump to: navigation, search

Code templates are prewritten code that you can easily insert into your code in the editor using the Ctrl+J keyboard shortcut. Code Templates help speed coding by saving keystrokes, inserting code with the necessary formatting, and placing your cursor at the location to continue coding.

Delphi for PHP includes a number of code templates including while block, update a table, table form, basic table, switch, select query, use_unit, for loop, for each, and more. It's also easy to add your own.

To create a code template:

  • Choose Tools Image:pathPDF.jpg Options to open the "Options" dialog box.
  • Select "Templates" under "Editor Options".
  • Click the "Add" button to open the "Add Code Template" dialog box.
  • Type a "Shortcut Name" and "Description" for the code template.Click "OK" to return to the "Options" dialog box.
  • Place your cursor in the "Code" edit field and type the contents of the code template.
  • Type a vertical bar character inside the template contents where you want the cursor located after the user inserts the code template.
  • Click "OK" when you are finished.

Image:optionscodetemplate.png

Image:addcodetemplate.png

To edit an existing code template

  • Choose Tools Image:pathPDF.jpg Options to open the "Options" dialog box.
  • Select the "Templates" under "Editor Options".
  • Select a code template in the "Templates" list.
  • Modify the content of the source code in the "Code" edit field.
  • Click the "Edit" button to open the "Add Code Template" dialog box and modify the template name and description.
  • Click "OK" when you are finished.

To use a code template

  • Place your cursor in your code at the location where you want to insert the contents of the code template.
  • Press  Ctrl+J to pop up the code template list.
  • Double-click the desired code template to insert it into your source code.

Image:insertcodetemplate.png

  • You can also type the template shortcut name at the cursor location, then press  Ctrl+J to insert the contents of the code template. For example, type fe and then Ctrl+J and the foreach code template will be inserted.
foreach ($ as $value) 
{
 
}
Personal tools