Sitecore Rendering Types

The topic of rendering types came up at the office the other day, and I wanted to write a quick post about them.  Rendering types are a group of classes that Sitecore uses to build up the controls on its pages using the presentation settings.  They handle the creation of the actual controls that Sitecore will use for rendering and allow for the Sitecore rendering engine to be extended.  You can use this mechanism to extend Sitecore by modifying how existing types of rendering work, or by adding your own custom rendering types.  This extension point can be useful for the times where you want to introduce functionality to Sitecore at a solution level; however I would typically recommend that you keep this to low-level functionality rather than high-level functionality, as your logic will be applied to every single rendering of your type in the solution, across all the websites.

As you’ll probably know, page items in Sitecore will have a layout and some renderings set for a particular device.  Sitecore converts these into controls by using the list of rendering types in the configuration (/sitecore/renderingControls).  Sitecore finds a type by matching the template of the rendering definition item to the template that the rendering type is registered against.  The rendering type then creates the appropriate control for Sitecore to add to the page.  It should be noted that, particularly in the case of sublayouts, the created control is not actually your sublayout user control, but rather the Sitecore.Web.UI.WebControls.Sublayout control (which will in turn create your user control, subject to caching and a few other bits and bobs).

Each rendering type implementation inherits from the abstract Sitecore.Web.UI.RenderingType class, which requires a GetControl method to be implemented.  This method takes some attributes and returns a control instance to Sitecore which can be added to the page.  For sublayouts, Sitecore uses the Sitecore.Web.UI.SublayoutRenderingType class by default, which as I previously mentioned creates a Sitecore.Web.UI.WebControls.Sublayout control.

The most typical use-case when overriding rendering types is to modify the behaviour of sublayouts by overriding the SublayoutRenderingType class to return a control that overrides some functionality inside the Sublayout class.  This can be used to support extensions to Sitecore’s HTML caching functionality, add some logic around whether a control renders, or add some logic around what a control renders.  If you only want to change some renderings in your solution, then I’d suggest that you consider creating a new template for these specific rendering items, and then add a new rendering type which targets that template.  The effect of this is that only the renderings belonging to your new type will exhibit your new functionality, giving you finer control over solution behaviour.

This is also probably one of the best ways to introduce a new type of rendering to the solution, but is not all that common but useful all the same if you have the requirement to do so.

So that’s the basics of rendering types.  I had originally intended to have an example alongside this post, but it didn’t quite work out for reasons that I might go into in a future post.  I would definitely suggest using them with care, but hopefully this has given you the basis to get started if you do need to use them.