Sitecore 7 基于树结构动态添加子布局

Sitecore 7 adding a sublayout dynamically based on tree structure

基于单个页面视图,我希望让我的内容结构动态构建页面。

举个例子:对于 GALLERY 模板的子项,它本身将具有使用 GALLERY ITEM 模板的子项,该模板定义了要在轮播中显示的每个图像;因此编辑器可以简单地添加多个项目,轮播将相应地缩放而不是固定字段(横幅、横幅 2 等)

目前,我无法理解如果存在该模板,我定义画廊 HTML 的子布局如何自动包含在此主页中。

编辑器不必手动添加子布局并为图库节点定义数据源,我希望主页沿树向下迭代并观察有一个 GALLERY 模板,因此知道它需要使用子布局并将其添加到主页占位符

根据此原则,页面将根据编辑器添加到页面的项目自行构建。

感谢任何建议或示例代码(使用网络表单);目前我不得不手动添加子布局,这对于内容编辑器来说似乎不直观 assemble 页面。

谢谢

如果您正确使用和配置 Page/Experience 编辑器,添加子布局和数据源是一个非常直观的过程,可以让您充分利用 Sitecore 的所有特性和功能,尤其是个性化和 A/B 测试。 这是您应该遵循的推荐做法。

就是说,如果您有情有可原的情况确实阻止您这样做,可以使用一种称为“Presentation Inversion of Control" which pulls renderings from items associated via the content tree. It was useful prior to the "unified page editor" and datasource wizards which appeared in Sitecore 6.4. There are various approaches to this 的旧技术,但最简单的方法是将 sublayout/web 控件放在页。

以下代码尚未在 Sitecore 7 上进行测试:

public partial class Gallery: System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
       PageItem page = Sitecore.Context.Item;
       //custom item contains logic for finding items to include
       foreach (Item galleryItem in page.GalleryItems)
       {
            string strDataSource = galleryItem.ID.ToString();
            RenderingReference[] renderings =
                galleryItem.Visualization.GetRenderings(Sitecore.Context.Device, false);
            foreach (RenderingReference rendering in renderings)
            {
                rendering.Settings.DataSource = strDataSource;
                this.Controls.Add(
                    rendering.RenderingItem.GetControl(rendering.Settings));
            }
        }
    }
}

但实际上,您应该正确实施页面编辑器。