Export (0) Print
Expand All

Statement Syntax 

You use statement blocks in text templates to control the flow of processing in the text template. Statement blocks allow you to structure templates to output things conditionally, or to iterate over data to output things repeatedly for each item in that data.

Code statements are delineated using opening (<#) and closing (#>) text template tags. The general syntax is:

<# StatementCode #>

Code statements should be written using the language declared in the language parameter of the template directive, and must compile successfully.

NoteNote

C# is the default text template language. For more information, see How to: Specify a Language in Text Templates.

The following example shows a code statement in a text template, in the C# language:

<# WriteLine("Hello"); #>

The following example shows a code statement on more than one line in a text template:

<#
    for(int i=0; i<4; i++)
    {
        WriteLine("Hello");
    }
#>

The following example shows an alternate version of the same statements:

<#
    for(int i=0; i<4; i++)
    {
#> 
<#
        WriteLine("Hello");
#>        
<#
    }
#>

Debugging

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

Community Additions

ADD
Show:
© 2014 Microsoft