Share via


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 by using the language that is declared in the language parameter of the template directive.

To add a statement to a text template

  • In text templates, use an opening "<#" tag and a closing "#>" tag to delineate code statements. 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
    
    <#
       Next
    #>
    

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

See Also

Other Resources

Adding Code to Text Templates

Using Built-in Directives in Text Templates

Generating Artifacts By Using Text Templates

Change History

Date

History

Reason

July 2008

Rewrote and refactored project.

Content bug fix.