Creating Code Templates

From FDT Documentation

Revision as of 04:23, 16 September 2010 by Aklement (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Code Templates

Default key binding: ctrl+space

FDT’s template, also refereed to as code snippets, allow for quick generation of commonly used 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 hitting the keystroke ctrl+space. When activated, begin typing the name of the template and then select it within the pop up windows that appears.

-video demo / screenshots of templates in action. Opening The Templates Editor To access FDT’s templates, open FDT’s Preferences window and navigate to FDT>Editor>Templates. Creating Templates 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. Context - The language context that the template will be active within while editing a file in the Editor View. Description - A description of the template. This appears both within the content assist pop up window and within the New Templates window. Pattern - The text that will inserted when a user selects the template via the pop up window.


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

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

-video demo / screenshots of templates in action. Editing Existing Templates With the Templates window open, choose a template to edit and click the Edit... button.. The Edit Template window will open and you can begin to edit the selected template. 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 and upon importing, 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. FDT will then convert the templates to XML and then ask you where you would like to save the generated XML. Importing Templates With the Templates window open click the Import... button. 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. 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.

Get FDT5