LibrarySites.Banner

Sitecore 7: Data Sources, Part 1: Enhancements

This blog post describes enhancements to the data source feature for presentation components in version 7 of the Sitecore ASP.NET web Content Management System. You can use data sources to specify data for each presentation component to retrieve.

Firstly, Sitecore 7 layout details always store the IDs of items, never their paths. As a result, there is no need to update references in layout details when you rename or delete data source items.

Secondly, Sitecore 7 tracks data sources in the links database, including data sources applied through page personalization and related features. When a user deletes a data source item, Sitecore 7 prompts them to remove, update, or break existing references.

screen capture of breaking links dialog

Thirdly, Sitecore 7 supports search queries as data sources. In this context, the data source can indicate a number of items. In fact, you could always use search query strings, identifiers in external databases, and other values that do not specify an individual Sitecore item as data sources, but Sitecore features that expect data sources to specify Sitecore items will not work as expected. 

In the Control Properties dialog, you can see the new Build Query command above the Data Source field in the General section.

screen capture of Build Query command highlighted in Control Properties dialog

You can use the Build Query command to specify a search query.

screen capture of build query dialog

In this case, the value stored as the data source for the control is +text:test;, which we will need to evaluate at in the presentation component.

What this means is that not only can you specify a data source dynamically, such as an item or a data source search query, but that data source can specify a number of items determined subsequently at runtime.

You can continue to specify individual data source items as you have in previous versions, and Sitecore will still provide the context item. Without some effort, only some types of presentation components support search queries as data sources. For example, XSL renderings do not support search queries. Even for types of presentation components that do support them, developers must apply search queries when necessary, for example in sublayouts and MVC presentation components. You can code such components to expect a search query, a single item, a single data source item or multiple data source items, or both a single data source item or multiple data source items.

Resources