In this article we’ll describe what standard values are in Sitecore, and how it can be used. We’ll go through the concept and then briefly touch where and how it should be used.
What is standard values in Sitecore
Standard values were first introduced in Sitecore 5.3 to overcome some of the issues experienced with the predecessors of standard values – “Masters”. In Sitecore 6 masters was completely removed and the concept of standard values took over. You may want to read this old blog post by Thomas Eldblom: No more masters.
Standard values are a way of having default or fallback values for fields in Sitecore, meaning that when items are created, you can specify a field value that should be used by default. This does not only account for custom fields you build, but also standard fields in Sitecore such as presentations and insert options. This means that you can specify a value on the standard values, and when you create a new item which inherits from this template, it will by default use the values specified on the standard values.
How to create Standard Values in Sitecore
You create standard values on the given template you want to add standard values for. Go to the template and click the options tab then click the standard values button.
If the options tab doesn’t appear, when you have selected the template, this is probably because you haven’t selected the builder tab, as it is only when this editor tab is selected that the contextual ribbon will occur.
Now that you have clicked the Standard Values button, there will automatically be created a subitem to the template called “__Standard Values”. This item is based on the template you created it from, and it is as such an actual item. You can change any field in this item, and then this will be the standard value for every item based on this template.
If you go to the template, you will see that the template points to the __standard values item and this is how Sitecore determines what item should be used for standard values:
This means that you in theory can rename or move the __standard values item, but I wouldn’t recommend doing so, as the “__standard values” name is hardcoded some places in the Sitecore API (at least for Sitecore 6.2).
Example of usage of standard values
If you go to your standard values item and enter a value in a field and then create an item based on the template, you will see that the text is filled in:
Another thing you will notice is the gray text next to the title which says “Standard values”. This is an indication for the editors, that this value is not actually set on the item, but pulled from the standard values.
When the editor changes the value and clicks save, the entered value automatically overrides the standard value of the field. When the standard value has been changed once, it cannot be restored by leaving the field empty. This is due to the fact, that it must be possible for an editor to leave the field blank.
Some fields have a little button in top of it, which says clear. If this button is clicked the standard values will be used again. If there isn’t a “clear” button – like on the single line text field – the editor can go to the “versions” tab and click “reset” in the Fields chunk. Then a dialog will appear where the editor can restore the standard values of whatever field(s) he or she likes:
If you add standard values for a template, and there already exists item based on this template, the standard values will be used, if the field has not been changed at some point or another by an editor.
Tokens in Standard Values
It is possible to enter tokens in the fields on the standard values, and then these will be replaced with other values, when the item is created. For instance you can let the name of an item be filled into a title field. This is done by entering the token $name in the field:
Now when you create a new item based on the NormalPage template, the name entered in the create item dialog will automatically be filled into the title field.
One thing you need to be aware of is that when you enter a token as a standard value, Sitecore will not replace values on already created items. Instead the value “$name” will be used in all the items, which hasn’t changed value since creation.
By default there are the following tokens available in Sitecore:
$name: Is replaced with the name of the created item
$parentname: Is replaced with the name of the parent to the created item
$date: Is replaced with the current date
$time: Is replaced with the current time
$now: Is replaced with current date and time
$id: Is replaced with the id of the created item
$parentid: Is replaced with the id of the parent to the created item.
You can add custom tokens yourself, which is described on Alistair Deneys blog
Standard values best practice
Besides using standard values for making the solution more user friendly for the editors, there are a couple of best practices, which you should follow, when using standard values. The concept should almost always be used for two other things: Assigning presentations and insert options. By following this advice, you will make your solution much more maintainable. Read more about assigning presentations to standard values in this blog post by Thomas Eldblom and read more about assigning insert options to standard values in this post by Alex de Groot.