Hello,
This forum has basically been abandoned in favor of the SDN forums:
http://sdn5.sitecore.net/Forum.aspx
This specific question is probably best addressed on the Developer
Talk > General Discussion forum:
http://sdn5.sitecore.net/forum//ShowForum.aspx?ForumID=10
I believe you could do this with nvelocity:
http://sdn5.sitecore.net/Articles/API/Using%20NVelocity.aspx
But I haven't tried and people seem to have had issues with this approach:
http://sdn5.sitecore.net/forum//ShowPost.aspx?PostID=6849
I would probably add an event handler for the item:saved event,
especially since you will probably end up with other save logic. You
could also do this with a pipeline:
http://sdn5.sitecore.net/forum//ShowPost.aspx?PostID=6227
Assuming an event handler, the logic would be something like:
If the item being saved is based on one of your templates
and the save is happening in the master database
and the value of that field is empty
then default the value to today's date
Information on events is here:
http://sdn5.sitecore.net/Articles/API/Using%20Events.aspx
Just to make it more complicated, updating data from within a save
handler can raise save events, which could cause infinite recursion.
This is generally resolved by adding a static hashtable to the handler
class:
private static Hashtable _htItemsInProcess;
public MyHandler()
{
_htItemsInProcess = new Hashtable();
}
The actual code to set the value would probably look something like this:
Sitecore.Data.Items.Item itm =
Sitecore.Events.Event.ExtractParameter(args, 0);
if ( ! _htItemsInProcess.ContainsKey( itm.ID ))
{
htItemsInProcess[itm.ID] = itm;
if ( itm.Database.Name.ToLower() == "master" &&
itm.Fields["myfield"] != null )
{
itm.Editing.BeginEdit();
itm.Fields["myfield"].Value =
Sitecore.DateUtil.ToIsoDate(DateTime.Now);
itm.Editing.EndEdit();
}
htItemsInProcess.Remove( itm.ID );
}