Export (0) Print
Expand All

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. The control logic is used to combine the text blocks with the data that a model holds to produce an output file.

You can use the Expression Syntax (Domain-Specific Languages) block to add a string that is generated in the culture that is specified in the culture parameter of the template directive. For more information, see How to: Specify a Culture in Text Templates.

To add an expression 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. In text templates, you delineate code expressions by using an opening "<#=" tag and a closing "#>" tag.

  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
    #>
    

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

NoteNote

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

Security

For more information, see Security of Text Templates.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft