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.
For example, you can define the following template. It inserts the declaration and initialization of the new SQL connection.
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.