c# - 为多语言 umbraco 站点复制内容

标签 c# content-management-system umbraco duplication

[编辑] 实际上,我已经被允许使用文档名称,这使它变得容易得多,但我仍然认为找出是否可能会很有趣。

我必须设置一个触发器来将内容复制到内容树上的不同分支,因为该站点将使用多种语言。我被告知我无法通过名称访问文档(因为它们可能会更改)并且我也不应该使用节点 ID(我不知道如何使用,过一段时间后将很难遵循结构)。

如何遍历树以将新文档插入其他语言的相关子分支?有办法吗?

最佳答案

您可以使用 Document.AfterPublish 事件在发布后捕获特定的文档对象。我会使用此事件处理程序来检查节点类型别名是否是您要复制的别名,然后您可以调用 Document.MakeNew 并传递新位置的节点 ID。 这意味着您不必使用特定的节点 ID 或文档名称来捕获事件。

例子:

using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic;
using umbraco.BusinessLogic;

namespace MyWebsite {
    public class MyApp : ApplicationBase {
        public MyApp()
            : base() {
            Document.AfterPublish += new Document.PublishEventHandler(Document_AfterPublish);
        }

        void Document_AfterPublish(Document sender, PublishEventArgs e) {
            if (sender.ContentType.Alias == "DoctypeAliasOfDocumentYouWantToCopy") {
                int parentId = 0; // Change to the ID of where you want to create this document as a child.
                Document d = Document.MakeNew("Name of new document", DocumentType.GetByAlias(sender.ContentType.Alias), User.GetUser(1), parentId)
                foreach (var prop in sender.GenericProperties) {
                    d.getProperty(prop.PropertyType.Alias).Value = sender.getProperty(prop.PropertyType.Alias).Value;
                }
                d.Save();
                d.Publish(User.GetUser(1));
            }
        }
    }
}

关于c# - 为多语言 umbraco 站点复制内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13122623/

相关文章:

c# - 使用 C# 向 Active Directory 注册更改通知

model-view-controller - Joomla!遵循 MVC 架构?

c# - 在 Umbraco 6 中构建联系表单

variables - 在 XSLT 中设置标志以通过循环检测第一次

c# - 启动进程后获取进程的友好名称

c# - 从数组创建选择列表

ruby-on-rails - 是否可以将 joomla/wordpress 与 ruby​​ on Rails 集成?

c# - 内容嵌套母版页未显示

c# - MVC : Retrieving form values after submitting

c++ - OpenSSL CMS 在 C++ 和 Objective-c 中加密