Code Templates Preferences
Code templates are code fragments that can be inserted at the current editing position. Oxygen JSON Editor includes a set of built-in templates for CSS, LESS, Schematron, XSL, XQuery, JSON, HTML, and XML Schema document types.
To configure Code Templates, open the Preferences dialog box and go to .
This preferences page contains a list of all the available code templates (both built-in and custom created ones) and a code preview area. You can disable any code template by deselecting it.
The following actions are available:
- New
- Opens the Code template dialog box that allows you to define a
new code template. You can define the following fields:
- 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.
- Edit
- Opens the Code template dialog box and allows you to edit an
existing code template. You can edit the following fields:
- 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.
- 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.
- Duplicate
- Creates a duplicate of the currently selected code template.
- Delete
- Deletes the currently selected code template. This action is not available for the built-in code templates.
- Export
- Exports a file with code templates.
- Import
- Imports a file with code templates that was created by the Export action.
- ${caret} - The position where the cursor is located. This variable can be used in a code template, in Author mode operations, or in a selection plugin.
- ${selection} - The currently selected text content in the currently edited document. This variable can be used in a code template, in Author mode operations, or in a selection plugin.
- ${ask('message', type, ('real_value1':'rendered_value1';
'real_value2':'rendered_value2'; ...), 'default_value', @id)} - To prompt for values
at runtime, use the ask('message', type, ('real_value1':'rendered_value1';
'real_value2':'rendered_value2'; ...), 'default-value'') editor variable. You can set
the following parameters:
- 'message' - The displayed message. Note the quotes that enclose the message.
- 'default-value' - Optional parameter. Provides a default value.
- @id - Optional parameter. Used for identifying the variable to reuse the answer using the ${answer(@id)} editor variable.
- type - Optional parameter (defaults to generic),
with one of the following values:Note: The title of the dialog box will be determined by the type of parameter and as follows:
- For url and relative_url parameters, the title will be the name of the parameter and the value of the 'message'.
- For the other parameters listed below, the title will be the name of that respective parameter.
- If no parameter is used, the title will be "Input".
Notice: Editor variables that are used within a parameter of another editor variable must be escaped within single quotes for them to be properly expanded. For example:${ask( 'Provide a date',generic,'${date(yyyy-MM-dd'T'HH:MM)}')}
Parameter generic (default) Format: ${ask('message', generic, 'default')} Description: The input is considered to be generic text that requires no special handling. Example: - ${ask('Hello world!')} - The dialog box has a Hello world! message displayed.
- ${ask('Hello world!', generic, 'Hello again!')} - The dialog box has a Hello world! message displayed and the value displayed in the input box is 'Hello again!'.
url Format: ${ask('message', url, 'default_value')} Description: Input is considered a URL. Oxygen JSON Editor checks that the provided URL is valid. Example: - ${ask('Input URL', url)} - The displayed dialog box has the name Input URL. The expected input type is URL.
- ${ask('Input URL', url, 'http://www.example.com')} - The displayed dialog box has the name Input URL. The expected input type is URL. The input field displays the default value http://www.example.com.
relative_url Format: ${ask('message', relative_url, 'default')} Description: Input is considered a URL. This parameter provides a file chooser, along with a text field. Oxygen JSON Editor tries to make the URL relative to that of the document you are editing. Note: If the $ask editor variable is expanded in content that is not yet saved (such as an untitled file, whose path cannot be determined), then Oxygen JSON Editor will transform it into an absolute URL.Example:
${ask('File location', relative_url, 'C:/example.txt')} - The dialog box has the name 'File location'. The URL inserted in the input box is made relative to the currently edited document location.
password Format: ${ask('message', password, 'default')} Description: The input is hidden with bullet characters. Example: - ${ask('Input password', password)} - The displayed dialog box has the name 'Input password' and the input is hidden with bullet symbols.
- ${ask('Input password', password, 'abcd')} - The displayed dialog box has the name 'Input password' and the input hidden with bullet symbols. The input field already contains the default abcd value.
combobox Format: ${ask('message', combobox, ('real_value1':'rendered_value1';...;'real_valueN':'rendered_valueN'), 'default')} Description: Displays a dialog box that offers a drop-down menu. The drop-down menu is populated with the given rendered_value values. Choosing such a value will return its associated value (real_value). Note: The list of 'real_value':'rendered_value' pairs can be computed using ${xpath_eval()}.Note: The 'default' parameter specifies the default-selected value and can match either a key or a value.Example: - ${ask('Operating System', combobox,
('win':'Microsoft Windows';'macos':'macOS';'lnx':'Linux/UNIX'),
'macos')} - The dialog box has the name 'Operating System'.
The drop-down menu displays the three given operating systems. The
associated value will be returned based upon your selection. Note: In this example, the default value is indicated by the osx key. However, the same result could be obtained if the default value is indicated by macOS, as in the following example: ${ask('Operating System', combobox, ('win':'Microsoft Windows';'macos':'macOS';'lnx':'Linux/UNIX'), 'macOS')}
- ${ask('Mobile OS', combobox, ('ios':'iOS';'and':'Android'), 'Android')}
- ${ask('Mobile OS', combobox, (${xpath_eval(for $pair in (['ios', 'iOS'], ['and', 'Android']) return "'" || $pair?1 || "':'" || $pair?2 || "';")}), 'ios')}
editable_combobox Format: ${ask('message', editable_combobox, ('real_value1':'rendered_value1';...;'real_valueN':'rendered_valueN'), 'default')} Description: Displays a dialog box that offers a drop-down menu with editable elements. The drop-down menu is populated with the given rendered_value values. Choosing such a value will return its associated real value (real_value) or the value inserted when you edit a list entry. Note: The list of 'real_value':'rendered_value' pairs can be computed using ${xpath_eval()}.Note: The 'default' parameter specifies the default-selected value and can match either a key or a value.Example: - ${ask('Operating System', editable_combobox, ('win':'Microsoft Windows';'macos':'macOS';'lnx':'Linux/UNIX'), 'macos')} - The dialog box has the name 'Operating System'. The drop-down menu displays the three given operating systems and also allows you to edit the entry. The associated value will be returned based upon your selection or the text you input.
- ${ask('Operating System', editable_combobox, (${xpath_eval(for $pair in (['win', 'Microsoft Windows'], ['macos', 'macOS'], ['lnx', 'Linux/UNIX']) return "'" || $pair?1 || "':'" || $pair?2 || "';")}), 'ios')}
radio Format: ${ask('message', radio, ('real_value1':'rendered_value1';...;'real_valueN':'rendered_valueN'), 'default')} Description: Displays a dialog box that offers a series of radio buttons. Each radio button displays a 'rendered_value and will return an associated real_value. Note: The list of 'real_value':'rendered_value' pairs can be computed using ${xpath_eval()}.Note: The 'default' parameter specifies the default-selected value and can match either a key or a value.Example: - ${ask('Operating System', radio, ('win':'Microsoft
Windows';'macos':'macOS';'lnx':'Linux/UNIX'), 'macos')} - The
dialog box has the name 'Operating System'. The radio button
group allows you to choose between the three operating systems.Note: In this example,
macOS
is the default-selected value and if selected, it would return macos for the output. - ${ask('Operating System', radio, (${xpath_eval(for $pair in (['win', 'Microsoft Windows'], ['macos', 'macOS'], ['lnx', 'Linux/UNIX']) return "'" || $pair?1 || "':'" || $pair?2 || "';")}), 'ios')}
- ${timeStamp} - The timestamp, which is the current time in Unix format. For example, it can be used to save transformation results in multiple output files on each transformation.
- ${uuid} - Universally unique identifier, a unique sequence of 32 hexadecimal digits generated by the Java UUID class.
- ${id} - Application-level unique identifier. It is a short sequence of 10-12 letters and digits that is not guaranteed to be universally unique.
- ${cfn} - Current file name without the extension and parent folder. The current file is the one currently open and selected.
- ${cfne} - Current file name with extension. The current file is the one currently open and selected.
- ${cf} - Current file as file path, that is the absolute file path of the currently edited document.
- ${cfd} - Current file folder as file path, that is the path of the currently edited document up to the name of the parent folder.
- ${frameworksDir} - The path (as file path) of the frameworks directory. When used to define references inside a framework configuration, it expands to the parent folder of that specific framework folder. Otherwise, it expands to the main frameworks folder defined in the preferences page.
- ${pd} - The file path to the folder that contains the current project file (.xpr).
- ${oxygenInstallDir} - Oxygen JSON Editor installation folder as file path.
- ${homeDir} - The path (as file path) of the user home folder.
- ${pn} - Current project name.
- ${env(VAR_NAME)} - Value of the VAR_NAME environment variable. The environment variables are managed by the operating system. If you are looking for Java System Properties, use the ${system(var.name)} editor variable.
- ${system(var.name)} - Value of the var.name Java System Property. The Java system properties can be specified in the command-line arguments of the Java runtime as -Dvar.name=var.value. If you are looking for operating system environment variables, use the ${env(VAR_NAME)} editor variable instead.
- ${date(pattern)} - Current date. The allowed patterns are
equivalent to the ones in the Java SimpleDateFormat class. Example:
yyyy-MM-dd.Note: This editor variable supports both the xs:date and xs:datetime parameters. For details about xs:date, go to: http://www.w3.org/TR/xmlschema-2/#date. For details about xs:datetime, go to: http://www.w3.org/TR/xmlschema-2/#dateTime.