Search code examples
c#razorumbracoumbraco6

Create umbraco server script which mirrors document contents including macros


I'm working on an umbraco project which has a lot of duplicate documents. I need multiple documents in my navigation structure which have the same content but a different title and a different position in the navigation tree. I created a documenttype with the generic property "copypage" (Type ContentPicker) where the editor can set which page's content should be mirrored. My current solution for this looks like

var page = Library.NodeById(Model.copypage);
@page.contents;

but this leads to problems with macros contained in the mirrored page.

Edit: My problem is that the macros on the original document access the documents children. Those children are not copied as children to the mirrored page. So my target is to execute @Html.Raw(umbraco.library.RenderMacroContent(page.contents.ToString(), Model.Id)) in the context of the original page.


Solution

  • I found an answer to my specific question myself. Changing every of my custom macros like the following solved my problem.

    var widgetsFolder = Model.WidgetsFolders.First();
    if (Model.HasValue("copypage")){
      var page = Library.NodeById(Model.copypage);
      widgetsFolder = page.WidgetsFolders.First();
    }