如何在Experience Manager中限制给定页面类型的内容类型

Alv*_*yes 6 tridion tridion-2011

Experience Manager(XPM)(SDL Tridion 2011 SP1的用户界面更新)允许管理员创建页面类型,其中包含与页面类似的组件演示,但也添加有关如何创建和允许其他内容类型的规则.

对于给定的页面类型,我想通过限制内容类型选择来简化作者的选项.

我知道我们可以:

  • 限制内容类型,以便对于给定的页面类型,作者只能创建某些预定义的内容类型
  • 在仪表板中,通过取消选择将上述内容完全限制为仅预定义的内容类型Content Types Already Used on the Page
  • 使用指定模式和模板组合的区域以及数量限制.作者只能将某些类型和数量的组件添加(拖放)到这些区域.例如,我们可以输出以下内容Staging来创建一个区域:
<div>
<!-- Start Region: {
  title: "Promos",
  allowedComponentTypes: [
    {
      schema: "tcm:2-42-8",
      template: "tcm:2-43-32"
    },
  ],
  minOccurs: 1,
  maxOccurs: 3
} -->
<!-- place the matching CPs here with template logic (e.g. TemplateBeginRepeat/ TemplateBeginIf with DWT) -->
</div>
Run Code Online (Sandbox Code Playgroud)
  • 作者可能仍会看到他们可能想要插入的组件(下图),但如果区域控制允许的内容,则无法添加它们
  • 但是,文件夹权限可以减少作者在插入内容库中可以查看/使用的组件

插入内容

我把它们都拿走了吗?XPM功能中的任何其他方式或可能的扩展考虑如何限制给定页面类型的允许内容?

Nic*_*kov 4

阿尔文,您几乎提供了问题中的大部分选项。如果需要自定义错误消息或更精细的控制级别,另一种选择是使用事件系统。订阅页面的保存事件启动阶段并编写一些验证代码,如果页面上存在不需要的组件呈现,则会抛出异常。

由于页面类型实际上是页面模板、页面上的任何元数据以及页面上的组件呈现类型的组合,因此我们需要检查我们是否正在处理所需的页面类型,以及是否遇到不符合要求的 CP。匹配我们想要的,我们可以简单地抛出异常。这是一些快速代码:

[TcmExtension("Page Save Events")]
public class PageSaveEvents : TcmExtension
{
    public PageSaveEvents()
    {
        EventSystem.Subscribe<Page, SaveEventArgs>(ValidateAllowedContentTypes, EventPhases.Initiated);
    }

    public void ValidateAllowedContentTypes(Page p, SaveEventArgs args, EventPhases phases)
    {
        if (p.PageTemplate.Title != "My allowed page template" && p.MetadataSchema.Title != "My allowed page metadata schema")
        {
            if (!ValidateAllowedContentTypes(p))
            {
                throw new Exception("Content Type not allowed on a page of this type.");
            } 
        }
    }

    private bool ValidateAllowedContentTypes(Page p)
    {
        string ALLOWED_SCHEMAS = "My Allowed Schema A; My Allowed Schema B; My Allowed Schema C; etc";  //to-do put these in a parameter schema on the page template
        string ALLOWED_COMPONENT_TEMPLATES = "My Allowed Template 1; My Allowed Template 2; My Allowed Template 3; etc"; //to-do put these in a parameter schema on the page template

        bool ok = true;
        foreach (ComponentPresentation cp in p.ComponentPresentations)
        {
            if (!(ALLOWED_SCHEMAS.Contains(cp.Component.Schema.Title) && ALLOWED_COMPONENT_TEMPLATES.Contains(cp.ComponentTemplate.Title)))
            {
                ok = false;
                break;
            }
        }

        return ok;
    }
}
Run Code Online (Sandbox Code Playgroud)