Code templates are code fragments that can be inserted quickly at the current editing
position. Oxygen XML Author Eclipse plugin includes a set of built-in code templates for CSS, 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 Ctrl +
Space 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:
- Open the
Preferences dialog box and go to .
-
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
- 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, and the
Ctrl key on other platforms.
- M2 represents the
Shift key.
- M3 represents the
Option key on macOS, and the
Alt key on other platforms.
- M4 represents the
Ctrl key on macOS, 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.
- 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 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
- Open the
Preferences dialog box and go to .
- Click the Export button to export all of your code templates
into an XML file.
- Save the XML file.
- Share the XML file with other members of your team.
-
Instruct them to open the
Preferences dialog box , go to , 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
- Open the
Preferences dialog box and go to .
- Select Project Options at the bottom of the dialog box. This
stores the preferences in the project file (.xpr).
-
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 Explorer view, the code templates will be
available in their content completion list.