JetBrains Rider 2021.3 Help

File templates

File templates are specifications of the default contents for new files that you create. Depending on the type of file you are creating, templates provide initial code and formatting expected in all files of that type (according to industry or language standards, your corporate policy, or for other reasons).

JetBrains Rider provides predefined templates for all supported file types suggested when you create a new file.

JetBrains Rider: Creating a file from template

Manage and configure file templates

  • Press Ctrl+Alt+S to open the IDE settings and select Editor | File Templates | Other Languages.

For more information, see Other Languages.

By default, the list of templates contains only predefined templates provided by JetBrains Rider. Some of them are internal, which means they cannot be deleted or renamed. JetBrains Rider shows the names of internal templates in bold. The names of templates that you modified, as well as custom templates that you created manually, are shown in blue.

The following procedures describe how to create file templates. Similar procedures can be used for creating include templates.

Create a new file template

  1. Press Ctrl+Alt+S to open the IDE settings and select Editor | File Templates | Other Languages.

  2. On the Files tab, click the Create Template button and specify the name, file extension, and body of the template.

  3. Apply the changes and close the dialog.

Copy an existing file template

  1. Press Ctrl+Alt+S to open the IDE settings and select Editor | File Templates | Other Languages.

  2. On the Files tab, click the Copy Template button and modify the name, file extension, and body of the template as necessary.

  3. Apply the changes and close the dialog.

Save a file as a template

  1. Open a file in the editor.

  2. From the main menu, select File | Save File as Template.

  3. In the Save File as Template dialog, specify the new template name and edit the body, if necessary.

  4. Apply the changes and close the dialog.

Syntax

File templates use the Velocity Template Language (VTL), which includes the following constructs:

  • Plain text rendered as is.

  • Variables that are replaced by their values. For example, ${NAME} inserts the name provided by the user when adding the file.

  • Various directives, including #parse, #set, #if, and others.

Start typing $ or # to see completion suggestions for available variables and directives.

For more information, see the VTL reference guide.

The following example shows the default template for creating a JavaScript class in JetBrains Rider:

/** * Created by ${USER} on ${DATE} */

In this template, ${USER} and ${DATE} are template variables.

When you create a new JavaScript file, this template generates a file with contents similar to the following:

/** * Created by John.Smith on 6/7/11 */
Last modified: 07 April 2022