Share via


Statement Syntax

You can use statement blocks in text templates to control the flow of processing in the text template. Statement blocks enable you either 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 as follows.

<# StatementCode #>

You should use the language declared in the language parameter of the template directive to write the code statements. The code statement must compile successfully.

Note

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

The following example shows a C# code statement in a text template.

<# 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");
#>        
<#
    }
#>

See Also

Tasks

How to: Add a Statement to Text Templates

Walkthrough: Creating and Running Text Templates

Other Resources

Adding Code to Text Templates

Using Built-in Directives in Text Templates

Generating Artifacts By Using Text Templates

Change History

Date

History

Reason

July 2008

Rewrote and refactored project.

Content bug fix.