Template Name Variables

  • 2 minutes to read

Template Name Variables allow you to define a template with several different expansions. You can include a variable part in the template name and place a text block that depends on the variable value in the template expansion.

Template Name Variables configuration is on the Editor | All Languages | Template Name Variables options page. For instance, the built-in Template Name Variable Type contains system types.


The left side of the page contains Variable Groups. Several groups can separate the values of a single variable with different contexts. The right side contains the name of the variable contained in the selected group, a list of its values, etc.


CodeRush attempts to simplify the variable values after substitution (for instance, the 'System.Boolean' becomes 'bool' in C#) if the checkbox This list holds .NET types is checked.


To insert a Template Name Variable into your template, insert the variable name surrounded by the "?" signs into the template name (?variable_name?). To insert the variable value into your expansion, use the Get(variable_name) text command.

A sample type-aware template that uses this Template Name Variable can be defined as follows:



The presented template uses the Field and BlockAnchor text commands. Refer to corresponding articles to learn more about them.

This creates a list of templates with the following names:

  • vib for bool
  • vic for char
  • vid for double
  • vis for string
  • vii for int
  • etc.

Adding a Template Name Variable


You can use the code editor's context menu to add a custom type as a Template Name Variable. Right-click the required type and select the Use Type in Templates... item. This adds a fully-qualified type name to the Custom Types group in the Neutral language.

To add a new Template Name Variable, follow the steps below:

  1. Create a new Variable Group using the New Variable Group button to store your variable.


  2. Name the new group.


  3. Fill the Variable Name field, then add name-value pairs to the list. The easiest way to add a list value is to fill the last row and press Enter.


  4. Test your Template Name Variable by creating a template that uses it. See the following example:


    You can now use it as follows:

    • dw1 expands as DayOfWeek.Monday
    • dw2 expands as DayOfWeek.Tuesday
    • etc.