如何从Sitecore中的当前项目渲染引用的项目?

时间:2012-10-19 05:10:55

标签: sitecore sitecore6

假设我有配置其演示文稿详细信息的项目。 在该项目中,我在树结构中的某处有TreelistEx字段保持引用(GUID)到10多个其他项目(不同模板),每个项目都有自己的演示详细信息(子布局)。

如何根据自己的设置在同一页面(当前项目)上显示所有参考项目? 我希望看到一个页面和10多个内容,每个内容都有自己的布局演示文稿。

2 个答案:

答案 0 :(得分:1)

我有类似的问题。以下是渲染子布局和xsl渲染的代码:

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

获得控件后,您可以将它们添加到占位符中,然后将它们渲染到页面中。

答案 1 :(得分:0)

每个项目都有自己的布局显示,这意味着您将获得一个完整的HTML文件...每个项目都有自己的<html>, <head>, and <form>标签。不用说,这会产生问题。

这就是说......这正是Server.Execute()的用途。循环遍历TreeList项,使用LinkManager获取项的URL,然后使用Server.Execute()获取呈现的输出。