This documentation is archived and is not being maintained.

How to: Add a Statement to Text Templates 

You can use text templates to generate code, XML, reports, or other artifacts from models. You can use Statement Syntax blocks to add Visual Basic or Visual C# code to your template. The code should be expressed using the language that is declared in the language parameter of the template directive.

To add a statement to a text template

  1. In Solution Explorer, right-click the text template file that you want to edit, and then click Open.

    The template opens in the editor.

  2. In text templates, you delineate code statements using an opening "<#" tag and a closing "#>" tag. Add statement tags to your text template with code, as shown in the following example. In this example, the code loops through each ModelType in ClassModel.Types:

       foreach(ModelType type in this.ClassModel.Types)
            // templateblocks

       Dim type as ModelType
       For Each type in Me.ClassModel.Types
            // template blocks

For an example of how to create a fully coded and running text template, see Walkthrough: Creating and Running Text Templates


To debug text templates, you must set the debug parameter of the template directive. For more information, see How to: Debug Text Templates.


For more information, see Security of Text Templates.

See Also