Adding a Template Type
The types of input accepted by SDL Tridion Sites 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 (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).
Step 3: extending Content Manager with your Template Type
Now that you have your custom mediator and (possibly) your custom content handler set up, you can make the Template Type available to Content Manager by configuring your Template Type in the Content Manager configuration file on the Content Manager server, Tridion.ContentManager.config. To do so, do the following:
- On your Content Manager server, access the config\ subfolder of
%TRIDION_HOME%. - Open Tridion.ContentManager.config for editing.
- In this configuration file, locate the
configuration/templateTypes/templateTypeRegistryelement, and add an element with the following structure:<add id="108" name="TEMPLATETYPENAME" mimeType="SOME/MIMETYPE" hasBinaryContent="false" contentHandler=""> <webDavFileExtensions> <add itemType="TemplateBuildingBlock" fileExtension="TEMPLATETYPEFILEEXTENSION" /> </webDavFileExtensions> </add> - If you created a content handler as well, add a
contentHandlerattribute to theaddelement that looks as follows:contentHandler="ClassName, FullyQualifiedAssemblyName"referencing your created class in the assembly that you have placed in the GAC. - Within the
configuration/tridion.templating/mediatorselement, add an element with the following structure:<mediator matchMIMEType="SOME/MIMETYPE" type="Your.NameSpace.ClassThatImplementsIMediator" assemblyPath="c:\path\to\assembly\with\ClassThatImplementsIMediator.dll" />
- The value of
idshould be unique, and be a number that is 100 or higher. - 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 area 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.