【问题标题】:Best way to find duplicate fields in Sitecore在 Sitecore 中查找重复字段的最佳方法
【发布时间】:2014-10-14 19:04:24
【问题描述】:

我有一些模板定义了“页面标题”或“页面名称”等相同的字段,但它们在不同的部分中定义。

当一个内容项目同时使用这两个模板时,当然在编辑项目时它们都会显示在各自的部分中。找到这些事件的最佳方法是什么?

我正在编写一些代码来检查所有模板,递归地查看模板继承,并找到重复项,但这已经失控了。

如何查看所有内容项本身以查看所有部分的所有字段,并查看是否存在重叠?这会让我到达我需要去的地方,但我不知道如何在给定 Sitecore 项目的情况下做到这一点。

【问题讨论】:

    标签: sitecore


    【解决方案1】:

    下面的代码循环遍历所有模板并检查重复的字段键:

    TemplateDictionary dict = TemplateManager.GetTemplates(Database.GetDatabase("master"));
    
    List<string> duplicates = new List<string>();
    
    string reportLine = "template '{0}': field '{1}' duplicated from templates '{2}'";
    
    foreach (KeyValuePair<ID, Template> templatePair in dict)
    {
        foreach (IGrouping<string, TemplateField> grouping in templatePair.Value.GetFields(true).GroupBy(f => f.Key).Where(f => f.Count() > 1))
        {
            duplicates.Add(String.Format(reportLine, templatePair.Value.FullName, grouping.Key, String.Join(", ", grouping.Select(g => g.Template.FullName))));
        }
    }
    

    它会以某种格式返回一个重复字段列表

    template 'System/Analytics/Engagement Automation/Engagement Plan State': field 'description' duplicated from templates 'System/Workflow/State, System/Analytics/Engagement Automation/Designer/Designer Item Parameters'
    

    【讨论】:

      猜你喜欢
      • 2018-05-26
      • 2011-06-21
      • 1970-01-01
      • 2016-11-21
      • 1970-01-01
      • 2012-07-30
      • 1970-01-01
      • 2010-09-29
      • 2014-06-23
      相关资源
      最近更新 更多