[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Collapse]CodeRush
  System Requirements
  Improve Performance
 [Expand]Features by Language
 [Expand]Getting Started
 [Expand]How To
 [Expand]Coding Assistance
 [Expand]Navigation and Search Tools
 [Expand]Static Code Analysis
 [Expand]Visualization Tools
 [Expand]Code Style Assistance
  Building Assistance
  Debugging Assistance
 [Expand]Refactoring Assistance
 [Expand]Unit Testing Assistance
 [Expand]Decompiling Tools
 [Expand]Configuration Options
 [Collapse]Extensibility
   Adding a Dictionary for the Spell Checker
  [Collapse]Custom Templates Creation
    Adding a Template
    Using Text Commands
    Referencing Namespaces
    Linking Identifiers
    Providing Input Fields
    Using Variables
    Iterating Through Elements
    Template Name Variables
    Alternative Template Expansions
    Text Commands
    String Providers
  [Expand]Context Providers
   Specify a Default Filter for the Jump to Symbol Window
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Using Variables

The CodeRush templates engine allows you to set global variables and insert their values into any other template. This feature is especially useful when expanding a template within another template. Variables and the ability to expand a template within another template enable you to extract a part of a template and insert that part into several other templates.

Text commands considered in this article are presented below.

  • To set a variable, use the «?Set(variable_name,value)» text command. This text command produces no output.
  • To insert the variable contents, use the «?Get(variable_name)» text command.
  • To expand another template, use the «:template_name» text command.

For example, you can define the following template. It inserts the declaration and initialization of the new SQL connection.

Note

Sub-templates should be given long descriptive names, which end-users would unlikely type. The sub-templates from the templates library are additionally surrounded with the hash (#) sign.

After defining the sub-template, you can use it as follows. Set the variables referenced by the sub-template, then place the text command expanding it.

The template presented above will expand as follows.

Is this topic helpful?​​​​​​​