Skip to main content
All docs
V22.2

How to: Create a Template from Scratch

  • 2 minutes to read
  1. Open the Editor | All Languages | Templates options page.

    The Templates page

  2. Choose the template language from the combo box in the page’s top left.

    Ext_Language

  3. Click the New Category button to create a separate category for your templates.

    Click "New Category"

  4. Enter the category name and enable the Make this a top-level folder option in the New Category dialog.

    The "New Category" dialog

    Click OK to create a category and close this dialog.

  5. To create a new template within a category, select the category and click New Template.

    Click "New Template"

  6. Enter the template name and click OK in the New Template dialog.

    New Template dialog

    Important

    The template name corresponds to its mnemonics. Type this name in your code to expand the template.

  7. Focus the Template Editor. Fill the Comment field and the template expansion code. For example, type “New SQL Connection” in the Comment field, and copy and paste the following template expansion code:

    SqlConnection sqlConnection = new SqlConnection();
    sqlConnection.ConnectionString = "Data Source=192.168.1.15; User id=; Password=;";
    sqlConnection.Open();
    try {
    
    }
    finally {
        sqlConnection.Close();
    }
    

    The screenshot below shows the “nsq” template with the specified settings:

    New template with code

  8. Specify the Context in the corresponding field to expand the template in certain conditions (optional).

    template context

    Click the ellipsis button to open the Select Context Provider dialog.

    Select context provider

    Choose a context provider from the list and click OK to insert it into the template.

  9. Configure the shortcut key that expands this template. Choose one of the following options in the Trigger this template with section:

    • Primary key - expands the template with the shortcut configured for the TemplateExpand command. This command is bound to the Space or Tab key depending on your selection in the Setup Wizard.
    • Secondary key - expands the template with the shortcut configured for the TemplateSecondaryExpand command (the default shortcut is Shift+Space).
    • Either key - expands the template both with Primary key and Secondary key.

    The resulting settings for the “nsq” template are shown below:

    Resulting options

  10. Click Apply and OK to apply the changes and close the Templates options page.

  11. Expand your new template. For example, type “nsq” and press Space in the code editor.

    Ext_Templates_NewResult