tags:

views:

47

answers:

2

What is the difference between the <# tag and the <#+ tag in T4?

+4  A: 

The docs explain:

Standard control blocks

A standard control block is a section of program code that generates part of the output file.

You can mix any number of text blocks and standard control blocks in a template file. However, you cannot place one control block inside another. Each standard control block is delimited by the symbols <# ... #>.

...

Class feature control blocks

A class feature control block defines properties, methods, or any other code that should not be included in the main transform. Class feature blocks are frequently used for helper functions. Typically, class feature blocks are placed in separate files so that they can be included by more than one text template.

Class feature control blocks are delimited by the symbols <#+ ... #>

For example, the following template file declares and uses a method:

<#@ output extension=".txt" #> Squares: <#
    for(int i = 0; i < 4; i++)
    {
#>
    The square of <#= i #> is <#= Square(i+1) #>. <#
    } 
#> That is the end of the list. <#+   // Start of class feature block
private int Square(int i) {
    return i*i; 
}
#>
Mark Rushakoff
+2  A: 

A class feature control block is a block in which you can define auxiliary methods. The block is delimited by <#+...#> and it must appear as the last block in the file. Ref

Mitch Wheat
The 'last block in the file' point is noteworthy.After you've used a <#+ #> block in a particular template file, you can no longer use regular <# #> blocks within that file.Consequently, your helpers/template members/nested classes need tob e grouped either at the end of a template file, or more frequently (for reuse) placed in a separate file and included.
GarethJ