我想在 Umbraco 的文档类型中为日期选择器字段设置一个默认值。
我该怎么做?
最佳答案
这可以在 Document.New 上使用事件轻松完成
只需创建一个新类(例如 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
}
}
}
关于Umbraco 文档类型字段默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4517663/