Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual Studio SDK
 How to: Generate HTML from Text Tem...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Domain-Specific Language Tools 
How to: Generate HTML from Text Templates 

Text templates can be used to generate reports as HTML documents you can publish on the Web. To generate HTML, include valid HTML in text blocks, and ensure that any expressions and write statements output valid HTML. The following procedure provides an example of creating a template that generates HTML.

To create HTML from a text template

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

    The template opens in the editor.

  2. Under your directives within your existing code, type in 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>
  3. Instead of double-clicking the generated text file to open it, right-click it and click View In Browser. Your output should display with HTML formatting applied.

    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

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker