Sitecore Links Database and Rendering (or Sublayout) DataSources

Posted on Feb 04, 2014 in  | No comments

Caveat: All code herein is built upon Sitecore 6.3 – mileage with other versions may vary

When we create areas of shared content, such as spotlights or banners, it’s common for us to reference these onto a page by adding a Rendering or Sublayout, then setting the DataSource to point to the content item we are interested in. The problem with this approach is two-fold: 1) Layouts are not versioned by default and 2) the Links reference counting system doesn’t handle items connected in this way.

Solving the first problem is simply a matter of marking the __Renderings field as both “not Unversioned” and “not Shared” – sorry for the double negatives. The template of interest is located at/sitecore/templates/System/Templates/Sections/Layout.

Solving the second problem is a little harder. After (incorrectly) assuming nobody would have tried to solve this already, I coded a solution last night, then Google’d and, you guessed it, there is already a solution to this problem posed by Alex Shyba and John West here: Credit where credit is due then, but I did it a different way so I’m going to share that anyway.

What I did was create an inherited LinksDatabase class. This class is responsible for the communication with the Links Database, and in normal Sitecore the hierarchy looks like this:

  • abstract LinkDatabase
    • SqlLinkDatabase
      • SqlServerLinkDatabase

I simply inherit from this class and override ::UpdateReferences() which allows me more control over what Links are registered for a given item. The reason for this approach is that I wanted the Links, at least from the DataSource perspective, to be limited to the LatestVersion of each item because I was using this system to help locate references to shared content. The LayoutField approach that Alex and John used doesn’t allow for this level of control. My code doesn’t account for broken links, which could be included easily enough, but I don’t actually care about that information for my purposes.

Here’s the code I used: