Edit online

Code templates are code fragments that can be inserted quickly at the current editing position. Oxygen XML Editor includes a set of built-in code templates for CSS, LESS, Schematron, XSL, XQuery, JSON, 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 Ctrl + Space (Command + Space on OS X) in Text mode). Also, in Text mode you can press Ctrl + Shift + Space 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. Open the Preferences dialog box (Options > Preferences) and go to Editor > Templates > 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.
    • Description - [Optional] The description of the code template that will appear in the Code Templates preferences page and in the tooltip message when selecting it from the Content Completion Assistant. HTML markup can be used for better rendering.
    • Associate with - You can choose to set the code template to be associated with a specific type of editor or for all editor types.
    • Shortcut key - [Optional] If you want to assign a shortcut key that can be used to insert the code template, place the cursor in the Shortcut key field and press the desired key combination on your keyboard. Use the Clear button if you make a mistake. If the Enable platform-independent shortcut keys checkbox is selected, the shortcut is platform-independent and the following modifiers are used:
      • M1 represents the Command key on MacOS X, and the Ctrl key on other platforms.
      • M2 represents the Shift key.
      • M3 represents the Option key on MacOS X, and the Alt key on other platforms.
      • M4 represents the Ctrl key on MacOS X, and is undefined on other platforms.
    • Content - Text box where you define the content that is used when the code template is inserted. An editor variable can be inserted in the text box using the Insert Editor Variables button.
  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 Ctrl + Space (Command + Space on OS X) 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. Open the Preferences dialog box (Options > Preferences) 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 open the Preferences dialog box (Options > Preferences), 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. Open the Preferences dialog box (Options > Preferences) 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 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.