0
votes

Let say I have item which has its presentation details configured. In that item I have TreelistEx field keeping reference (GUIDs) to 10+ other items (different templates) somewhere in the tree structure each of them has their own presentation details (sublayouts).

How can I present all reference items on the same page ( as current item) based on their own settings? I would like to see one page and 10+ pieces of content each with its own layout presentation.

2

2 Answers

1
votes

I had a similar problem. Here is the code for rendering sublayouts and xsl renderings:

public IEnumerable<Control> GetRenderingControls(Item item)
        {
            // Loop through all renderings on the item
            foreach (RenderingReference rendering in item.Visualization.GetRenderings(Context.Device, false))
            {
                // Get the path to the Sublayout
                string path = rendering.RenderingItem.InnerItem["Path"];
                switch(rendering.RenderingItem.InnerItem.TemplateName.ToLower())
                {
                    case "xsl rendering":
                        // Create an instance of a XSL
                        XslFile xslFile = new XslFile();
                        xslFile.Path = path;
                        xslFile.DataSource = item.Paths.FullPath;
                        xslFile.Parameters = GetParameters(xslFile);
                        yield return xslFile;
                        break;
                    case "sublayout":
                        // Create an instance of a sublayout
                        Sublayout sublayout = new Sublayout();
                        sublayout.Path = path;
                        sublayout.DataSource = item.Paths.FullPath;
                        sublayout.Parameters = GetParameters(sublayout);
                        yield return sublayout.GetUserControl();
                        break;
                    default:
                        throw new Exception(string.Format("Unknown rendering template - {0}", rendering.RenderingItem.InnerItem.TemplateName));
                }
            }
        }

Once you get the Controls you can add them to a placeholder and they will be rendered to the page.

0
votes

Each item with its own layout presentation implies you are getting an entire HTML file... each item will have its own <html>, <head>, and <form> tags. Needless to say, that's going to create a problem.

That being said... This is exactly what Server.Execute() is for. Loop through your TreeList items, use LinkManager to get the URL for the item, and then Server.Execute() to get the rendered output.