Umbraco 文档类型字段默认值

标签 umbraco

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

我该怎么做?

最佳答案

这可以在 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
    }
  }
}

关于Umbraco 文档类型字段默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4517663/

相关文章:

azure - Umbraco.config 存储在 Azure 云服务中的哪里?

c# - 更改 Umbraco 7.1.4 管理 URL

content-management-system - 如何手动更改 Umbraco 中文档的链接

Umbraco 7 - Umbraco 文档类型的只读属性

css - 如何在不安装软件包的情况下在 umbraco cms 中使用 sass 而不是 style.css?

forms-authentication - 对 umbraco 站点的所有请求都重定向到登录页面

c# - 为什么 Umbraco WYSIWYG 在标签链接前放置正斜杠?

azure - 将 umbraco 部署到 Azure

javascript - Umbraco - 多媒体选择器 - 分割和输出图像

seo - 在 MVC 中为 Umbraco 中的 SEO 呈现 View