Umbraco Type Field Default Value Field

I would like to set the default value for the date picker in the document type in Umbraco.

How can i do this?

+3
source share
3 answers

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 (e.g. 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
    }
  }
}
+5
source

This can be achieved using the first sebastiaans link. As the page says, you simply enter $ date $ as the standard value. The package then inserts the current date when the user creates a document of this type.

0
source

Source: https://habr.com/ru/post/1781806/


All Articles