-
Notifications
You must be signed in to change notification settings - Fork 50
Sample Solution
The sample solution contains three projects:
- Sitecore.Master - The sample TDS project. This contains sample content items, templates and fields that are used to demonstrate code generation.
- SampleLibrary - A C# class library project that will be the destination of the generated classes
- Extensions - A C# class library project containing useful extension methods that can be used in your T4 template
-
Helpers.tt -
This file contains simple helper functions that may be useful to T4 template authors. This helper file can be referenced in your own .tt files via the
<#@ include file="Helpers.tt" #>
directive. -
GlassHeader.tt
This file is used to generate a set of
using
statements and base classes required by the Glass framework. - GlassItem.tt This file is used to generate code for Glass Item Mapper interfaces and classes.
-
VelirHeader.tt
This file is used to generate a set of
using
statements required by the CIG framework. - VelirItem.tt This file is used to generate code for CIG classes.
- ItemPaths.tt This file generates a set of classes that allows you to have Sitecore items paths with intellisense as demonstrated by Kern Herskind Nightingale
- MDDocHeader.tt This file is used to generate a header for the Markdown documentation file.
- MDDocItem.tt This file is used to generate Markdown formatted documentation for the items in the TDS project.
- The Extensions Project - See Using Extensions Methods
Depending on the framework you are generating code for, there are assemblies that are required in order to compile the project. Please see the $(SolutionDir)\lib\Readme.txt
file for a list of assemblies you must reference.
Visual Studio needs to be running as an Administrator in order to compile. This is due to a post build step on the Extensions project. Please see Using Extensions Methods for more information.
By default the TDS project is configured to generate Markdown documentation; this isn't typically what you would use code gen for. To generate code for either Glass or CIG:
- Go to the code generation properties of the TDS project
- Change the "Code Generation Target File" to
TdsT4CodeGeneratedFile.cs
- Change the "Header Transform File" to
GlassHeader.tt
orVelirHeader.tt
- Change the "Base Project Transform File" to
GlassItem.tt
orVelirItem.tt
- Right click on the TDS project and choose "Re-Generate code for all items"
Now, in the SampleLibrary project you should have a file called TdsT4CodeGeneratedFile.cs
. Within that file you should have classes that conform to your specific framework!
There are more advanced configurations of code generation as well.
- Each item in your TDS project can configure a different T4 template. This would allow you to generate different code for different trees of items.
- You can pass custom parameters with the item by using the 'Data' property.