开发者

Umbraco Document Type Field Default Value

I would like set a default value for a d开发者_StackOverflow社区ate picker field in a Document Type in Umbraco.

How can I do this?


This can be easily done using Events, on Document.New

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

Just create a new class (eg. 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
    }
  }
}


You could use the Standard Values or the Default Values for Umbraco package.


That can be achieved with sebastiaans first link. As it says on the page you just put in $date$ as the standard value. Then the package will insert current date when the user creates a document of this type.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜