0

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

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

4

2 回答 2

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

获得控件后,您可以将它们添加到占位符中,它们将被呈现到页面上。

于 2012-10-19T08:45:06.087 回答
0

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

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

于 2012-10-22T17:56:16.097 回答