在 umbraco 中为节点创建默认子节点

Create default childs to node in umbraco

我想知道如何强制节点只创建一个其他类型的子节点?

我有 'hotel' 节点,我想添加一个 'rooms' 节点和一个 'facilities' 节点('rooms' 创建 'room' 和 'facilities' 创建 'facility')

by default when i will create hotel the system will create this 2 folders or to force him that he can create only one each

我更喜欢用管理系统来做(如果可能的话),但后面的代码也很好!

在此先感谢所有帮助者!

就我而言,我不知道通过 Umbraco 后台实现这一目标的方法。

但是,您可以使用 ContentService Events 取消创建该特定页面(如果它已经创建)。每次您尝试在 CMS 中创建节点时,ContentServiceSaving 方法都会启动。

public class ContentServiceEventsController : ApplicationEventHandler
{
    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
      ContentService.Saving += ContentServiceSaving;
    }

    private void ContentServiceSaving(IContentService sender, SaveEventArgs<IContent> e)
    {

      switch (e.Entity.ContentType.Alias)
      {
        case "RoomsDocumentTypeAlias":
        case "FacilitiesDocumentTypeAlias":

        // Do your logic to detect if your Hotel node "Hilton eilat queen of sheba" 
        // already contains either a Rooms node or a Facilities node underneath.
        // If so, cancel the creation of the event of a new one.
        e.Cancel = true;
        break;

        default:
               break;
      }
    }