Templating Base Project
The project (download link below) provides a rich starting functionality for developers about to build templates in .NET and in Visual Studio.
The project can be easily adapted for an organization's templating assembly which we will be uploaded to Tridion and then provide templates to be combined in Page and Component Templates using the Template Builder tool.
The important part of the project is the included TemplateBase.cs class. This class contains many useful methods which are needed throughout the devlopment of Tridion templates.
Methods and Properties
Listing all of these methods will be quite an extensive exercise but here are details of some of the more common ones:
An XmlNameSpaceManager already initialized with several XML namespaces such as: tcm, xlink and xhtml
Returns the component object that is defined in the package for the template
Returns the page object that is defined in the package for the template
Returns the list of structure groups of the current publication
Returns the string value for an item in the package with the specified name
And many, many more!
How to start using
Notice that the TemplateBase class must be included in the project you upload into Tridion as your templating assembly, otherwise you will see errors about not being able to find the class.
To use the base functionality all one needs to do is inherit from the base class instead of extending the ITemplate interface in the TOM.NET library.
Here is a short code example and the result in the Template Builder:
class ExtendedTemplate : TemplateBase
public override void Transform(Engine engine, Package package)
Logger.Info("this is a logger from a deriving class of the template base class");}
Make sure to change the template name for the uploaded assembly in the AssemblyInfo.cs file, in there you can also specify the target folder URI to which the assembly and template classes will be uploaded
Participated in creating this base project
Jeremy Grand-Scrutton (SDLTridion)
Nuno Linhares (SDLTridion)
Yoav Niran (SDLTridion)
Thanks also to:
Will Price (SDLTridion) and Peter Jan Beemster (SDLTridion) for their input and assistance.
Version 1.2 - Updated 09/06/2009
This new version of the base project includes many new features together with some bug fixing.
Some of the new additions:
- Added even more utility and helper methods such as: IsPage, IsComponent, GetFieldType, etc.
- Added support for the new version of the XSLT Mediator: to easily load extension objects from a Tridion TBB.
- Added a generic class for loading and using XML lists from Tridion (GetListItems)
- Added the Expression Item Retriever which is a new and useful way of accessing field values and items in Tridion through an easy to learn expression syntax. (see the 'Expression Item Retrieval.doc' in the zip for more information).
Example of such an expression: �::content/paragraphs/title�
which will retrieve the 'title' embedded field in the second 'paragraph' field of a component.
Version 1.3 - Update 09/07/2009
This new version of the base project includes a new class called "ItemFieldWrapper", this class wraps any of the ItemField implementations available in the .NET API and expose the values of those as string values.
Since most usage of component field values is to output them to a page as strings, accessing these values becomes cumbersome and annoying since the API doesnt support getting the values of Date, Number or Keyword (to name a few) fields as strings and so an explicit cast must be carried whenever we wish to access these values.
The ItemFieldWrapper takes care of these casting for us and gives us a single point of access to the values of any of the field types available.