Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates 如何更新特定Sitecore模板的多个现有项的字段值?_Templates_Field_Sitecore - Fatal编程技术网

Templates 如何更新特定Sitecore模板的多个现有项的字段值?

Templates 如何更新特定Sitecore模板的多个现有项的字段值?,templates,field,sitecore,Templates,Field,Sitecore,在Sitecore 7.2中,我有一个文件夹,其中包含许多需要转换为Bucket的项目。我在该模板的标准值中检查了bucketable(根据官方文档),所以所有新项目都将进入bucket,但我还需要在近百个现有项目中更新该字段。有什么聪明的方法吗 此外,之前我遇到过类似的情况,当时我需要更新某些模板的所有现有项的禁用字段,因此可能有一些通用解决方案?据我所知,有两种方法可以做到这一点-代码简单,PowerShell模块智能(如果已安装)。不幸的是,我不认为Sitecore桌面中有专门的接口来实现

在Sitecore 7.2中,我有一个文件夹,其中包含许多需要转换为Bucket的项目。我在该模板的标准值中检查了bucketable(根据官方文档),所以所有新项目都将进入bucket,但我还需要在近百个现有项目中更新该字段。有什么聪明的方法吗


此外,之前我遇到过类似的情况,当时我需要更新某些模板的所有现有项的禁用字段,因此可能有一些通用解决方案?

据我所知,有两种方法可以做到这一点-代码简单,PowerShell模块智能(如果已安装)。不幸的是,我不认为Sitecore桌面中有专门的接口来实现这一点

1.从C代码进行大规模更新:

private void UpdateAllFieldsRecursively(Item parentItem, string templateName, string fieldName, string newValue)
{
    if (parentItem != null)
    {
        using (new SecurityDisabler())
        {
            foreach (Item childItem in parentItem.Children)
            {
                if (childItem.Fields[fieldName] != null && childItem.TemplateName == templateName)
                {
                    using (new EditContext(childItem))
                    {
                        childItem[fieldName] = newValue;
                    }
                }

                if (childItem.HasChildren)
                {
                    UpdateAllFieldsRecursively(childItem, templateName, fieldName, newValue);
                }
            }
        }
    }
}

// and below there is the call to recursive mehod
const string parentNode = "/sitecore/content";
var database = Sitecore.Context.Database;
var parentItem = database.GetItem(parentNode);

UpdateAllFieldsRecursively(parentItem, "Article", "Bucketable", "1");
2.PowerShell ISE。执行以下代码(您可能需要根据您的场景稍微修改):

该脚本递归地从/sitecore/content开始,并更新所有文章模板的Bucketable字段。将这些值替换为您需要的任何值


这里有一篇博客文章描述了这一点:

对于你的bucket场景,如果我理解正确的话,你只想用现有的项目更新一个文件夹,使其成为bucket。听起来您已经正确配置了它。您不需要转到每个现有项并更新
Bucketable
设置。如果已将其设置为标准值,则只需同步bucket,其余部分由Sitecore处理

就批量编辑项目而言,@martin miles的任何一种解决方案都可以工作。我可能会选择PowerShell方法,但请记住,它是一个尖锐的工具,因此在执行完整运行之前,值得在较小的数据集上测试您的命令或脚本。另一个要考虑的选项是工具。这是更改当前目录下所有子体的示例:

find -r (sf bucketable 1)
find -r (sf bucketable 1)