【问题标题】:Duplicating content on save for a multilingual umbraco site为多语言 umbraco 网站在保存时复制内容
【发布时间】:2012-10-29 13:31:19
【问题描述】:

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

我必须设置一个触发器以将内容复制到内容树上的不同分支,因为该站点将使用多种语言。有人告诉我,我不能按名称访问文档(因为它们可能会更改),我也不应该使用节点 ID(不是说我会知道如何使用,一段时间后会变得难以遵循结构)。

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

【问题讨论】:

    标签: c# content-management-system umbraco duplication


    【解决方案1】:

    您可以使用 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));
                }
            }
        }
    }
    

    【讨论】:

    • 非常感谢。实际上,我使用 Document.New 对其进行了排序,因为没有必要立即发布。这么说,你的要简洁得多。
    • 实际上会帮助处理另一部分,所以再次感谢伙计。
    猜你喜欢
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    • 2014-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多