T 4 beginners – part 3
this is the 3rd post on this series.
in this post we will focus on basics T4 Control blocks.
you can download the code sample from here.
T4 Control blocks is where dynamic text is added into the template output,
this is the heart of T4 concept
(C# is the default language but you can change it to VB).
Standard control blocks
A standard control block is a section of program code that generates part of the output.
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 <# … #>.
the above snippet include control block that write the current day of week.
this is the code it generate:
Expression control blocks
An expression control block evaluates an expression and converts it to a string and insert it into the output file.
the syntax of expression control blocks is using the <#= … #> syntax instead of <# … #> .
both the WriteLine and the ; were omit.
the following snippets is using expression control block combine with standard control block which
use for iterations:
lines 1-3, start the iterations.
line 5, write text block which embedded expression control block that write the current iteration count.
lines 6-8, close the iterations.
the output will look like:
the control block is what T4 is doing, create dynamic section