Adding a Template Type
The types of input accepted by SDL Web for creating Template Building Blocks: Compound Templates, .NET assembly, C# fragment, Dreamweaver templates and XSLT templates, are normally sufficient for most use cases. If necessary, you can add template types to the Modular Templating Framework by creating template instances that use these types.
Step 1: creating an assembly with a class that implements IMediator
The first step is to create a class that implements the IMediator interface. This interface is similar to the ITemplate interface. The only real difference is that the Transform() method receives a Template argument. The implementation of the Transform method should take the template contents, and execute it on the current package (the Configure method can typically be left empty).
Place this class in an assembly that is stored on the Content Manager server.
Step 2: adding your Template Type to the configuration
Template Types are configured in the Content Manager configuration file. If you create your own Template Type, you must edit this configuration file in a plain-text or XML editor and add the Template Type. The configuration file, called Tridion.ContentManager.config, is located in the config\ subfolder of %TRIDION_HOME%.
In this configuration file, locate the configuration/templateTypes/templateTypeRegistry element, and add an element with the following structure:
<add id="8" name="TEMPLATETYPENAME" mimeType="SOME/MIMETYPE" hasBinaryContent="false" contentHandler="">
<webDavFileExtensions>
<add itemType="TemplateBuildingBlock" fileExtension="TEMPLATETYPEFILEEXTENSION" />
</webDavFileExtensions>
</add>
Next, within the configuration/tridion.templating/mediators element, add an element with the following structure:
<mediator matchMIMEType="SOME/MIMETYPE" type="Your.NameSpace.ClassThatImplementsIMediator"
assemblyPath="c:\path\to\assembly\with\ClassThatImplementsIMediator.dll" />
Some important notes on the attributes of these elements:
- The value of
idshould be unique, and be the next available number. - The
mimeTypeandmatchMIMETypeattributes in the two elements should be equal, and unique. Preferably, the MIME type (which can be anything) should not appear as a Multimedia Type. - The
nameis used in the GUI to name the type, and may not contain spaces. - The
hasBinaryContentshould be false for text-based templates, and true if the template is binary (such as the .NET assembly Template Type). - If you do not want to use Template Building Blocks of this type in a Compound Template, change the
itemTypefromTemplateBuildingBlockto a different value. - The
fileExtensionshould be unique, that is, no other Template Type should have the same value for itsfileExtensionattribute. This extension is used when your Templates are accessed through WebDAV. The
fileExtensionshould not be a file extension that is in use by a Multimedia Type. To check if the file extension is in use, do the following:- Access the Content Manager Explorer Web site as an administrator-level user.
- From the navigation tree, access the node . The content are shows a list of configured Multimedia Types.
- Check the list of Multimedia Types for a type of file that commonly has the extension you want to specify. If you are unsure, double-click the Multimedia Type item to open it in a popup, then check File Extensions.
Step 3 (optional): creating a content handler
Create a content handler if one or both of the following is true:
- You intend to validate the content of your templates, and generate errors if the template content fails validation.
- Your templates contain references to Content Manager items (using Content Manager URIs or WebDAV URLs) that you intend to manage.
A content handler can process references to Content Manager items when a template is stored or retrieved. Doing this has the following advantages:
- The reference is managed in the Content Manager, so that the item to which the template refers cannot be removed.
- The reference can be updated to be Publication-independent, so that the reference still works if a template is used in a Child Publication.
To create a content handler for a Template Type, do the following:
- Create a class that extends the
AbstractTemplateContentHandlerclass and implement its methods to extract and replace Content Manager references in the content of the template and/or to validate the contents of the template. - Put this class in an assembly, and place that assembly in the GAC (Global Assembly Cache) of the Content Manager server (that is, you can put this class in the same assembly as your
IMediatorimplementation, but you must place it in the GAC for the content handler, for which the assembly must be signed). - In the Template Type
addelement, set the value of thecontentHandlerattribute as follows:contentHandler="ClassName, FullyQualifiedAssemblyName"referencing your created class in the assembly that you have placed in the GAC.