Custom rendering
Customizing the rendering process involves manipulating the output produced by the rendering process, which typically combines a content item with a Template.
Customize rendering for the following reasons:
- You have a specific modification that you want to apply to all publishable content that is to be published. In this scenario, you could also create a Template Building Block and add it as the last Template Building Block in all your Templates. But especially if you have many different Templates, a custom renderer can be easier.
- You want to publish items of an item type that is currently not resolved or rendered. In this scenario, you would need to add a custom resolver to resolve this item type, a custom renderer to render it, and implement code on the receiving Content Delivery end to process the incoming content. The specifics of this scenario are not explored further here.
To create a custom renderer:
- Create a custom renderer class in .NET
-
To start, implement your business logic in a custom renderer class. This class implements the
IRendererinterface, found in the Tridion.ContentManager.Publishing.Rendering namespace. - Create a .NET assembly for this file and add it to your Content Manager configuration
-
Create an assembly from this .NET class and add it to the Global Assembly Cache (GAC). Next, access your Content Manager server and open the Content Manager configuration file in a plain-text or XML editor. This file is called Tridion.ContentManager.config and is located in the config\ subfolder of
%TRIDION_HOME%.In this file, find the
<rendering>section, which contains a<mappings>section with a number ofaddelements, one for each combination of a publishable item type and a type of template. Here is one suchaddelement:<add itemType="Tridion.ContentManager.ContentManagement.Component" templateType="CompoundTemplate"> <renderers> <add type="Tridion.ContentManager.Templating.TemplatingRenderer" assembly="Tridion.ContentManager.Templating, Version=5.4.0.1110, Culture=neutral, PublicKeyToken=360aac4d3354074b"/> </renderers> </add>The
itemTypeattribute indicates the type of items being rendered (Component in this case),templateTypespecifies the type of Template for which the renderers are specifies (Compound Template), and the<renderers>element contains a list of renderers for this type (by default, just the one standard renderer that SDL Web ships with), specifying the class and assembly information.To add your custom renderer, add a new
addelement below the one already present. For example, to add aMyCustomRenderer.NET class, contained in an assembly calledMyCompany.Tridion.CustomRendering, to the list of renderers for theComponentitem type rendered by a Compound Template, add a newaddelement inside the<renderers>and specify the class and assembly information:<add itemType="Tridion.ContentManager.ContentManagement.Component"> <renderers> <add type="Tridion.ContentManager.Publishing.Legacy.Resolving.ComponentResolver" assembly="Tridion.ContentManager.Publishing.Legacy, Version=5.4.0.1110, Culture=neutral, PublicKeyToken=360aac4d3354074b"/> <add type="MyCompany.Tridion.CustomRendering.MyCustomRenderer" assembly="MyCompany.Tridion.CustomRendering, Version=1.0.0.0, Culture=neutral, PublicKeyToken=eb4399ad2323ad58"/> </renderers> </add> - Optional: add custom configuration
-
If your custom renderer class requires custom configuration, SDL Web expects to find such configuration in the same Tridion.ContentManager.config file, in the section named as specified in the code. To create and specfiy such a section, do the following:
In the
<configSections>section at the top of the file, add asectionelement, provide a name, and set thetypeattribute to a class that can handle the contents of the section. For example, if the section will contain a simple named property, use the default .NET classSystem.Configuration.NameValueSectionHandler:<section name="My.Tridion.CustomRendering" type="System.Configuration.NameValueSectionHandler" />Next, at the bottom of the file, add a configuration section with the name you specified and fill it with content that the class you specified can handle. In this example, the section contains an
addelement with akeyand avalueattribute:<My.Tridion.CustomRendering> <add key="locale" value="ja-jp" /> </My.Tridion.CustomRendering>
- Apply your changes
-
Finally, save and close the Tridion.ContentManager.config file and from your list of Windows Services, restart the Windows service called
Tridion Content Manager Publisher. Also restart IIS, COM+ and your Service Host. This applies your changes.