Sitecore’s sublayout datasource, brilliant! Or maybe not?

One of the strengths of Sitecore is the DMS (Digital Marketing System). DMS collects user information and allows you to personalize the website based on the user’s profile.

One of the possible personalizations is changing the content of a sublayout by changing its datasource.

This sounds great, but sitecore made one big design flaw!

The items in the datasource are not stored by ID, but by the selected items path! This means that changing one of the item names in the tree of the selected item (or the selected item name itself) will break the datasource. Moving the item will also break the datasoure. Beware of that!!!

Sitecore announced to fix this in a future version.

I’m also not very happy about the way you have to retrieve the datasource item:

Item item;
string datasource = ((Sitecore.Web.UI.WebControls.Sublayout)this.Parent).DataSource;
if (!string.IsNullOrEmpty(datasource) {
    item = Sitecore.Context.Database.SelectSingleItem(datasource);
}
The following two tabs change content below.
I'm a software developer from Utrecht. Interested in DDD, continuous delivery, new technologies & frameworks.

Latest posts by Vincent Keizer (see all)

1 Comment

  1. Sitecore 7 stores the id of the item instead of path. You can also use Attributes[“sc_datasource”] to retrieve the datasource.

Leave a Reply

Your email address will not be published.

*