gpt4 book ai didi

Umbraco 文档类型字段默认值

转载 作者:行者123 更新时间:2023-12-01 11:57:45 24 4
gpt4 key购买 nike

我想在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com