【问题标题】:How to render referenced items from current item in Sitecore?如何从 Sitecore 中的当前项目呈现引用的项目?
【发布时间】:2012-10-19 05:10:55
【问题描述】:

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

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

【问题讨论】:

    标签: sitecore sitecore6


    【解决方案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));
                    }
                }
            }
    

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

    【讨论】:

      【解决方案2】:

      每个项目都有自己的布局表示意味着你得到了一个完整的 HTML 文件...每个项目都有自己的&lt;html&gt;, &lt;head&gt;, and &lt;form&gt; 标签。不用说,这会产生问题。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-09
        • 2014-11-19
        相关资源
        最近更新 更多