Creating Code Templates

From FDT Documentation

Revision as of 12:28, 28 September 2010 by Aklement (Talk | contribs)
Jump to: navigation, search

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). [1].

Contents

Opening The Templates Editor

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

Creating Templates

With the Templates window open, click the New... button to begin creating your own template [3]. 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 [4].
  • Context - The language context that the template will be active within while editing a file in the Editor View [5].
  • Description - A description of the template. This appears both within the content assist pop up window and within the New Templates window [6].
  • Pattern - The text that will inserted when a user selects the template via the pop up window [7].

After setting the Name, Context and Description, fill in what text you wish to be inserted into your file when this template is selected [8]. 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 [9]. Users can add their own variables by using the syntax ${} and adding your own description between the braces [10].

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 [11]. The Edit Template window will open [12] and you can begin to edit the selected template [13]. 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 [14]. FDT will then convert the templates to XML and then ask you where you would like to save the generated XML [15].

Importing Templates

With the Templates window open click the 'Import...' button [16]. 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' [17]. If the provided template file is valid, FDT will add the templates to the available templates. If the templates valid is invaild, e.g. an error in the .XML syntax, FDT will notify with an error message [18].

Get FDT5