Bgl86
Bgl86

Reputation: 737

Copy Presentation Details to new PlaceHolder programmatically Sitecore 7.2

currently I am working on a page that generates a print view of a specific item. So this means I dont need all the stuff from my MainLayout like Navigation etc.

For this reason I have created a new Layout that only has a placeholder. Lets call this PrintLayout.aspx:

<sc:placeholder ID="PlPrint" runat="server" key="phPrintOutput"></sc:placeholder> 

In the code behind I have a method that fetches the renderings from the item, but I am stuck at the point where I want to copy them to my phPrintOutput Placeholder on the fly:

public void AddPresentationDetailsToPlaceHolder(Item item)
{
  List<RenderingReference> renderings = item.Visualization.GetRenderings(Sitecore.Context.Device, false).ToList();
  foreach(RenderingReference r in renderings)
  {
    // How can I apply the renderings on the fly to my phPrintOutput Placeholder??
  }
}

Of course it is very important that every sublayout keeps it current datasource. Any help would be appreciated, thank you all

Upvotes: 0

Views: 198

Answers (1)

Hishaam Namooya
Hishaam Namooya

Reputation: 1081

You only require to add the control to the placeholder. To do so, please see the code below:

public void AddPresentationDetailsToPlaceHolder(Item item)
{
  List<RenderingReference> renderings = item.Visualization.GetRenderings(Sitecore.Context.Device, false).ToList();
  foreach(RenderingReference r in renderings)
  {
      if(r.RenderingID == new ID("Rendering Id you want to be displayed on layout"))
      {
          this.PlPrint.Controls.Add(r.GetControl());
      } 
  }
}

This will automatically add the rendering to the layout.

Upvotes: 0

Related Questions