Umbraco文档类型字段默认值

时间:2010-12-23 10:01:52

标签: umbraco

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

我该怎么做?

3 个答案:

答案 0 :(得分:5)

可以使用Document.New

上的事件轻松完成

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
    }
  }
}

答案 1 :(得分:0)

答案 2 :(得分:0)

这可以通过sebastiaans第一个链接来实现。正如它在页面上所说,你只需将$ date $作为标准值。然后,当用户创建此类型的文档时,包将插入当前日期。

相关问题