Sitecore Development / Kim Hornung

Monday, March 05, 2007

Fun with Standard Values and versioning

Sitecore v5.3 introduced the concept of "Standard Values" which gives you dynamic, default values for the different data fields for each template in Sitecore. A really excellent feature that can be used for things like assigning masters to template, specifying default categories for news items, etc. etc.

At a recent SCD1 training, a developer asked me whether it is possible to create several versions for the standard values. In other words: Can you make the "fall-back" value change over time? Or just keep track of your previous standard values?

I was a bit sceptic, but Sitecore stores the standard values as any other item in Sitecore, so it might work.

So what happened?
I created a simple test case:

  1. First I added some random text to version 1 of the Standard Values for the "Page" template of my trusty demo site

  2. I tested that this worked as expected when showing a Preview (it did, which is hardly surprising since this is the normal way of using Standard Values)

  3. Then I added a second version to the Standard Values and filled in some text

  4. I opened a Preview and was happy to see that the version 2 values was displayed

  5. Now the fun part: I entered a start date for version 2 in the "Publish Restrictions" dialog box so that version 2 was set to be published in a week from now. That gave a quite unexpected result!

After specifying the publishing date, the menu on my website suddenly looked like this:

Notice how "KH TEST" and "Company History" are still displaying their normal menu title, while all other menu items are displaying the data from the Standard Values.

But why does the Standard Values override the values for all these items???

It took me a few seconds to figure out what is happening:

  1. When Sitecore resolves the fields for an item, it look for a Standard Value for all data fields that are NULL
  2. Most of the items on the demo site has a NULL value for all the "Lifetime" fields (i.e. the fields that specify the publishing dates for each individual version)
  3. Therefore, Sitecore will use the Standard Value for the "Liftetime" for all these items - and since the Standard Value has a publishing date in the future, Sitecore will not display the regular data in the fields (but will instead display any Standard Values for the data fields, disregarding the fact that publishing dates have been specified for the Standard Values item)

So what happens is very logical (maybe except for the fact that the standard values apparently doesn't respect publishing restrictions). But it was definitely not the result I expected :o)

  • It is possible to create multiple versions for Standard Values in Sitecore (for example to keep a backup of the previous values), as long as you don't specify any publishing restrictions (such as specifying publishing dates for the most recent version of the Standard Values item).
  • Specifying publishing dates for Standard values will sooner or later lead to confusion!
    All items with a "NULL" value in the publishing dates will use this date, and their regular content will only be available within the publishing dates that are specified for the Standard Values (outside this interval, older versions of the item will be displayed if they have explicit publishing dates specified - if no explicit publishing dates are specified for any versions, the Standard Values will be displayed instead).


Post a Comment

Subscribe to Post Comments [Atom]

<< Home