Creating Code Templates

From FDT Documentation

Jump to: navigation, search
File 05-013.png

FDT’s code templates, also referred to as code snippets, allow for quick generation of user defined code. Although FDT ships with many templates pre-installed, users can edit existing templates, create new ones and even share templates with other FDT developers. Similar to Advanced Code Completion, code templates are activated by typing part or all of the template's name and use the keystroke Ctrl+Space (OSX) or Ctrl+Space (Windows) Img preview.png.


Opening The Templates Editor

05 002.jpg

To access FDT’s templates, open FDT’s Preferences window and navigate to FDT>Editor>Templates.

Creating Templates

05 003.jpg

With the Templates window open, click the New... button to begin creating your own template. With the New Template window open we see various fields to fill in:

  • Name -The name of the template that will be searched when code completion is activated Img preview.png.
  • Context - The language context that the template will be active within while editing a file in the Editor View Img preview.png.
  • Description - A description of the template. This appears both within the content assist pop up window and within the New Templates window Img preview.png.
  • Pattern - The text that will inserted when a user selects the template via the pop up window Img preview.png.

After setting the Name, Context and Description, fill in what text you wish to be inserted into your file when this template is selected Img preview.png. To enhance the functionality of templates, users can add variables to their templates. Variables allow for more powerful and flexible templates by analyzing the context of the template when activated and adding text based on that context. FDT ships with a number of pre-defined variables which can be accessed by clicking the Insert Variable... button Img preview.png. Users can add their own variables by using the syntax ${} and adding your own description between the braces Img preview.png.

Tip - When multiple instances of a custom variable exist, all instances of that variable will be simultaneously be updated.

Edit Existing Templates

With the Templates window open, choose a template to edit and click the Edit... button Img preview.png. The Edit Template window will open Img preview.png and you can begin to edit the selected template Img preview.png. When finished, click OK to save the template.

Importing and Exporting ( Sharing ) Templates

Templates can be easily shared and even versioned via CVS. FDT templates are distributed via XML which FDT creates upon exporting. Upon importing, FDT will interpret the XML and add the templates to the Templates Editor.

Exporting Templates

With the Templates window open highlight the templates you wish to export, it can be just one or all of them. With your chosen templates selected, click the Export... button Img preview.png. FDT will then convert the templates to XML and then ask you where you would like to save the generated XML Img preview.png.

Importing Templates

With the Templates window open click the Import... button Img preview.png. FDT will then ask you to select the file which contains the templates you wish to add to your existing list of templates. Navigate to a valid .XML file and then click Open Img preview.png. If the provided template file is valid, FDT will add the templates to the available templates. If the templates are invaild, e.g. an error in the .XML syntax, FDT will notify with an error message Img preview.png.

Wrap Up

This tutorial was short and sweet, but keep an eye out as more tutorials continue to be published.

Get FDT5