Umbraco文档类型字段默认值

Nam*_*ami 3 umbraco

我想在Umbraco的文档类型中为日期选择器字段设置默认值.

我怎样才能做到这一点?

Axi*_*ili 5

这可以使用Document.New上的Events轻松完成

http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events/overview-of-all-events

只需创建一个新类(例如UmbracoEvents.cs)

using System;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
using Examine;

public class UmbracoEvents: ApplicationBase
{
  /// <summary>Constructor</summary>
  public UmbracoEvents()
  {
    Document.New += new Document.NewEventHandler(Document_New);
  }

  private void Document_New(Document sender, umbraco.cms.businesslogic.NewEventArgs e)
  {
    if (sender.ContentType.Alias == "News")
    {
      sender.getProperty("date").Value = DateTime.Today; // Set the date for a new News item to today
    }
  }
}
Run Code Online (Sandbox Code Playgroud)