Duplicate content to save umbraco multilingual site

[Edit] I was really allowed to use document names, which makes it a lot easier, but I still think it would be interesting to know if this is possible.

I need to set a trigger to duplicate content for different branches in the content tree, as the site will be in several languages. I was told that I cannot access documents by name (since they can change), and I should not use node identifiers (not that I know how to do this, after a while it will be difficult to follow the structure).

How can I go through a tree to insert a new document into the corresponding branches in other languages? Is there any way?

+4
source share
1 answer

You can use the Document.AfterPublish event to catch a specific document object after publishing it. I would use this event handler to check the alias of the node type you want to copy, then you can call Document.MakeNew and pass the node identifier to the new location. This means that you do not need to use a specific node identifier or document name to catch the event.

Example:

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)); } } } } 
+3
source

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


All Articles