Georg Jung
Georg Jung

Reputation: 1167

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.

Upvotes: 0

Views: 281

Answers (2)

Georg Jung
Georg Jung

Reputation: 1167

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();
}

Upvotes: 0

Astuanax
Astuanax

Reputation: 667

The most tested solution for rendering content from another page is the uComponents macro "RenderTemplate". i

You can build your templates with Razor, or whatever it is that you like, then use the ID of the page to render it in another template. This is often used to render a number of widgets on another page. All you need is the ID of the page to be rendered. The macro also supports rendering with a different template.

<umbraco:Macro runat="server" Alias="RenderTemplate" NodeIds="1,11,12" CurrentPage="1" EntriesPerPage="10" AltTemplateId="0" UseChildNodes="0" />

Another solution would be to use the umbraco property "umbracoInternalRedirectId". This property redirects to another page, but keeps the URL of the initial request, masking the url for the other page.

Upvotes: 1

Related Questions