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.
Creating a custom renderer consists of several steps.
- Step 1: creating 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 an assembly from this .NET class and add it to the Global Assembly Cache (GAC). - Step 2: extending Content Manager with your custom Renderer
-
Now that you have your custom Renderer set up, you can make it available to Content Manager by configuring it in the Content Manager configuration file on the Content Manager server, Tridion.ContentManager.config. To do this, 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
<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 specified (Compound Template), and the<renderers>element contains a list of renderers for this type (by default, just the one standard renderer that SDL Tridion Sites ships with), specifying the class and assembly information. - Add a new
addelement below the one already present. For example, to add aMyRenderer.NET class, contained in an assembly calledMyTemplatingExtension, 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="MyRenderer" assembly="MyTemplatingExtension, Version=1.0.0.0, Culture=neutral, PublicKeyToken=eb4399ad2323ad58"/> </renderers> </add>
- On your Content Manager server, access the config\ subfolder of
- Step 3: adding custom configuration (optional)
-
If your custom renderer class requires custom configuration, SDL Tridion Sites expects to find such configuration in the same Tridion.ContentManager.config file, in the section named as specified in the code. To create and specify 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>
- Step 4: Applying 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.