How to: Generate HTML from Text Templates

You can use text templates to generate reports as HTML documents for the Internet. Text templates let you generate HTML and include valid HTML in text blocks. These templates ensure that any expressions and write statements will output valid HTML. The following procedure shows how to create a template that generates HTML.

To create HTML from a text template

  1. Under the directives in your existing code, type your html text.

    For example:

    <#@ template inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation"#>
    <#@ ClassDiagramExample processor="ClassDiagramExampleDirectiveProcessor" requires="fileName='Sample.testcd'" #>
    <#@ output extension=".htm" #>
    <html>
    <h1>ModelClass</h1> 
    <ul>
    <#
       foreach(ModelType type in this.ClassModel.Types)
       {
    #>
    <#
       if(type is ModelClass)
       {#>
    <li/><#=type.Name#>
    <#
       }
    #>
    <#
    }
    #>
    </ul>
    </html>
    
  2. Right-click the generated file and then click View In Browser.

Output that has HTML formatting should be displayed.

See Also

Tasks

Walkthrough: Creating and Running Text Templates

Other Resources

Generating Specific Kinds of Artifacts from Text Templates

Adding Code to Text Templates

Generating Artifacts By Using Text Templates

Change History

Date

History

Reason

July 2008

Rewrote and refactored project.

Content bug fix.