Tuesday, December 22, 2009

The importance of the Data Source attribute

I know that most of you probably already know the importance of actively using the data source attribute on renderings. This has become even more important with the Online Marketing Suite.

So if you are new to Sitecore or just haven't thought about using the data source yet, read on.

I am going to use the Nicam site as an example and show how we can use the same control to output different content based on the source attribute.

In the right hand image there is a control outputting the text "D3X" on a red background with a link to the D3X page. The content item that holds the information for the control is not the current context item, but rather an item that the developer has pointed to when chosen to output that control on this specific page.









The content item looks like this:


Now to change the content I could just change the values of the content item, but if I have used the "D3X - red" content item on other pages and wants to keep the content it would be smarter to use the data source attribute to point to another content item like the one above "D3X - grey".

This way I can reuse the same control over and over on different pages (or on the same page) but change the actual content by pointing to different content items through the data source attribute.

The data source attribute is found in the "Layout Details" when clicking on a control or in Design mode when highlighting a control and then clicking on properties.

Setting the data source attribute actually means that you point to a different "context" item than the one requested by the URL. So you don't need to specify anything when extracting content from a field.

for example outputting the text from a single line text field would just be:

<sc:text field="field name">

Because omitting the "select" statement means that Sitecore will use the context item.

Online Marketing Suite
Creating controls that uses the source attribute is especially important when using the OMS for personalization or multi variant testing.

This is because the Personalization rules and MV testing both uses the data source to change the content item displayed through a control based on the rules that the user set up.

Drop me a comment if you want more info about using the data source when setting up MV testing or personalization rules.

1 comment:

  1. In addition to using layout details to set the data source statically, you can also use conditional rendering (part of the rules engine) to set the data source dynamically.

    http://sitecorejohn.spaces.live.com/blog/cns!960125F1D4A59952!399.entry

    http://sdn.sitecore.net/reference/sitecore%206/rules%20engine%20cookbook.aspx

    ReplyDelete