Code Block

A code block is a piece of code that will be compiled when the template is to be executed.

The code must follow normal C# or VB (or your own language if you have extended TextTemplate) rules and be legal code in the location you have placed it.

A code block starts with the characters <% and ends with the characters %>.

%> has no meaning outside of a code block, and <% has no meaning inside of a code block.

Note that the code block doesn't output anything to the template output by default, but you have access to the built-in variable generatedTemplateOutput if you need to do this manually.

This block type is typically used for flow control and bigger blocks of statements.


    for (int index = 1; index <= 5; index++)
    <%= index %>

Here we have two such code blocks, and also one expression block. The two code blocks are:
  • "for (int index = 1; index <= 5; index++) , the start of the loop up to and including the brace
    * ", the end of the loop

Last edited Jan 20, 2011 at 10:37 PM by lassevk, version 1


No comments yet.