User Tools

Site Tools


t4_syntax.htm
Navigation:  T4 Template Language Reference >Directives Previous pageReturn to chapter overviewNext page

T4 Template Directives

<;#@ DirectiveName [ParameterName = “ParameterValue”] #>

All parameter values must be surrounded by double quotation marks. If the ParameterValue contains quotation marks, they must be escaped with the \ character.

Directives are usually the first elements in a template file or an included file. You should not place them inside a code block <;#…#>, or after a class block <;#+…#>.

Line 15: <;# this._OutputFile = this.OutputFile;#>

just the value set in the 'OutputFile' within the property directive to the internal _OutputFile variable.

Line 16: <;# Create(this._OutputFile);#>

calls an internal method that creates a file on disk to receive the generated text (code or other text). It corresponds to our Win32 counterpart #CREATE.

Line 17:

*

is a text block, as there are no template directives surrounding it. Text blocks are copied to the output 'as is', with no further processing.

Line 18: ' Listing for Dictionary: <;#= this.DataDictionary.FileName #>

mixes a text block: '- Listing for Dictionary: ' with an expression block:

<;#= this.DataDictionary.FileName #>

You use expression blocks in text templates to add strings to the generated text output. In this case we're asking for the name of the Dictionary that we're processing. Expression blocks are delineated by using the <;#= template tag. The syntax is: <;#= ExpressionCode #>

Lines 19-49 use code blocks. The syntax for a code block is: <;# Code block #>

Code blocks can generate template output. In our template the code block uses a few nested foreach loops to walk the dictionary. We're using a mix of text blocks and expression blocks to write the details of the dictionary to the output file. Code blocks can use any available .NET APIs. In this template we're using the DataDictionary API to output the Dictionaries collections and properties; Tables, Columns, Keys and Relationships.

I hope this walk-through has provided a good introduction to the new template syntax used in AppGen.Net.  For those who are thinking of writing some T4 templates the attached example is a good starting point to get familiar with the essentials. Next time we'll go a bit deeper into the template syntax.

t4_syntax.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1