Share via


How to: Add an Expression to Text Templates

You can use text templates to generate code, XML, reports, or other artifacts from models. A text template file contains a mixture of text blocks and control logic. Use the control logic to combine the text blocks with the data from a model to produce an output file.

The Expression Syntax (Domain-Specific Languages) block contains strings that are generated in the culture that is specified in the culture parameter of the template directive. Use the Expression Syntax (Domain-Specific Languages) block to add an expression. For more information, see How to: Specify a Culture in Text Templates.

To add an expression to a text template

  1. Use an opening "<#=" tag before each code expression and a closing "#>" tag after each.

  2. Add the following expression to the template.

    <#
       foreach(ModelType type in this.ClassModel.Types)
       {
          if (type is ModelClass)
          {
    #>
             <#= type.Name #>
    <#
          }
       }
    #>
    
    <#
       Dim type as ModelType
       For Each type in Me.ClassModel.Types
          If TypeOf(type) Is ModelClass Then
    #>
             <#= type.Name #>
    <#
          End If
       Next
    #>
    

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.