Search This Blog

Wednesday, July 31, 2013

Template text file with a .tt file extension in c#

The basic idea of the template toolkit is to parse an input file and transform it into an output file. The input file is a template—a text file with a .tt file extension. The output file will also contain text, and the text can be C# code, Visual Basic code, Web Forms code.

How can create .tt file in asp.net ???


Add text.tt file:





Input of text.tt file:

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ output extension=".txt" #>
    <#int top = 10;
       for(int i = 0; i<=top; i++) { #>
    The square of <#= i #> is <#= i*i #>
    <# } #>

Output of text.txt file:

     The square of 0 is 0
        The square of 1 is 1
        The square of 2 is 4
        The square of 3 is 9
        The square of 4 is 16
        The square of 5 is 25
        The square of 6 is 36
        The square of 7 is 49
        The square of 8 is 64
        The square of 9 is 81
        The square of 10 is 100

No comments :