Edit online

Code Templates

Code templates are code fragments that can be inserted quickly at the current editing position. Oxygen XML includes a set of built-in code templates for CSS, LESS, Schematron, XSL, XQuery, JSON, HTML, and XML Schema document types. You can also define your own code templates for any type of file and share them with others.

Code templates are displayed with a symbol in the content completion list (Enter in Author mode or in Text mode). Also, in Text mode you can press to see a complete list of the available code templates. To enter the code template at the cursor position, select it from the content completion list or type its code and press Enter. If a shortcut key has been assigned to the code template, you can also use the shortcut key to enter it.

How to Create Code Templates

To create a code template, follow these steps:
  1. and go to Editor > Content Completion > Code Templates.
  2. Click New to open a code template configuration dialog box.
    Tip:
    You can use one of the existing code templates as a starting point by selecting that template and clicking Duplicate.
    Figure 1. Code Template Configuration Dialog Box
  3. Configure your template using the fields in the code template configuration dialog box:
    • Name - The name of the code template.
    • Associate with - You can choose to set the code template to be associated with a specific type of editor or for all editor types.
  4. Click OK to save your new code template.

Result: Your code template can now be selected using the Content Completion Assistant (Enter in Author mode or in Text mode). The code templates are displayed with a symbol.

How to Share Code Templates

There are two ways to easily share all of your code templates with other members of your team:

Method 1: Export/Import
  1. and go to Editor > Templates > Code Templates.
  2. Click the Export button to export all of your code templates into an XML file.
  3. Save the XML file.
  4. Share the XML file with other members of your team.
  5. Instruct them to , go to Editor > Templates > Code Templates, click the Import button, and select the file you sent them.

    Result: The code templates will be now available in their content completion list.

Method 2: Share Project
  1. and go to Editor > Templates > Code Templates.
  2. Select Project Options at the bottom of the dialog box. This stores the preferences in the project file (.xpr).
  3. Share the project file with the other members of your team. For example, you can commit it to your version control system and have them update their working copy.

    Result: When they open the updated project file in their Project viewProject Explorer view, the code templates will be available in their content completion list.

Tip:
It is also possible to configure certain actions that function similar to code templates and add them to the content completion list for a particular framework. You could then share the whole framework with other members of your team.