The issue with resetting standard values and token thread on the Sitecore Developer Network (SDN) forums prompted me to write this blog post that explains how to replace standard values tokens in existing items in the Sitecore ASP.NET web Content Management System (CMS). For more information about standard values, see The Sitecore Data Definition Reference. For more information about standard values tokens, see The Sitecore Data Definition Cookbook.
When you create an item, Sitecore expands tokens in standard field values for that item and updates the item you created accordingly. For example, Sitecore replaces an instances of the token $name in the fields of the item the data template with the name of the item. The supported tokens are:
If you reset a field to its standard value, Sitecore does not replace these tokens, so they can appear in the field value. To address this issue, I wrote a rules engine action to replace the tokens in field values. This solution is intended for use with the solution described in the blog post Apply Rules to All Items in the Sitecore ASP.NET CMS. This solution invokes the rules engine against the items you specify, and I assume you would use it with the "where true (actions always execute)" condition. For more information about the rules engine, see The Sitecore Rules Engine Cookbook and the blog post All About the Sitecore ASP.NET CMS Rules Engine.
This solution replaces standard values tokens with the appropriate values at the time of replacement. For example, if you have renamed the item since you created it, this solution replaces $name with the current name for the item, not the original name, $parentid and $parentname with information about the current parent, and $date, $time, and $now with the current date and time, not the date and time at the item's creation. The action does not expand standard values tokens in standard values definition items or branch template definition items.
Download the untested prototype, which contains the following files:
A more immediate solution would expand standard values tokens immediately after resetting a field. You could override the Reset Fields dialog to include this logic, but that would not handle field resets through API methods (specifically the Sitecore.Data.Fields.Field.Reset() method). A better solution might use an item:saved event handler, but I’ve written enough about event handlers, I wanted to reuse the rules engine infrastructure I developed yesterday, and by the time you discover that you have this issue, you probably want to run this logic against an entire branch of items). For more information about events, see the blog post All About Events in the Sitecore ASP.NET CMS. It should be relatively easy to port this code to an event handler, in which case you should factor the reset logic into a helper class that both the action and the handler can invoke. If you implement that solution, please attach the code and Web.config include file to the SDN forum thread linked above and comment on this blog post. For more information about Web.config include files, see the blog post All About web config Include Files with the Sitecore ASP.NET CMS.
Actually, I think you can use the same rule action to expand standard values tokens immediately after users and API methods reset fields without the need to write a separate event handler. Create a rule under the /sitecore/system/Settings/Rules/Item Saved/Rules item, use the "where true (actions always execute)" rule, and select the action. Also, I didn't really think about the impact of clones. For information about clones, see www.sitecore.net/.../Sitecore-CMS-6-4-Cloning.aspx
Hi John, I've built an alternative solution to this problem: sitecorejunkie.com/.../ Kind regards, Mike
Thanks Mike. Some context info: www.sitecore.net/.../All-About-Standard-Values-in-the-Sitecore-ASPNET-CMS.aspx