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
-
In Solution Explorer, right-click the text template file you want to edit and then click Open.
The template opens in the editor.
-
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> -
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.
Note |
|---|
| To debug text templates you must set the debug parameter of the template directive. For more information, see How to: Debug Text Templates. |
Security
See Also