gpt4 book ai didi

powershell - 使用 Sitecore Powershell 将基本模板附加到模板

转载 作者:行者123 更新时间:2023-12-03 15:36:06 26 4
gpt4 key购买 nike

我是 Sitecore PowerShell(以及一般的 PowerShell)的新手,我想生成一个脚本,将模板作为基本模板添加到某个上下文文件夹下的 ChildItem 模板列表中。

由于 __Base 模板是标准值而不是常规字段,我不确定是否有可用的语法将 GUID 附加到它使用的多列表字段(管道分隔)。

这是我尝试过的

$master = Get-Database master;
$translationTemplate = $master.Templates["Path/To/Template/Needed/Translatable"];
$calloutTemplate = $master.Templates["Path/To/Example/Callout"];

#$translationTemplate;

$calloutTemplate += $translationTemplate;

我可以使用 Get-ChildItem -recursive 递归获取所有子项,但是对于测试运行,我只想在一个名为 Callout 的模板项上进行尝试。这是 $calloutTemplate 的 View ,显示它有一个 BaseTemplates 部分和一个 Fields 部分(应该包括 __Base 模板):

enter image description here

如果 Powershell 中没有针对 Sitecore 的解决方案,那么 Sitecore Rocks 查询分析器 CRUD 操作是否可行?

最佳答案

基本上你要找的脚本是:

$templateToExtend = Get-Item 'master:/templates/Path/To/Example/Callout'
$templateToAdd= Get-Item 'master:/templates/Path/To/Template/Needed/Translatable'

# Make sure we're not adding it again if it's already there
if(-not ($templateToExtend."__Base template" -match "$($templateToAdd.Id)"))
{
"Adding '$($templateToAdd.Name)' to '$($templateToExtend.Name)' Base templates"
$templateToExtend."__Base template" = "$($templateToExtend.'__Base template')|$($templateToAdd.Id)"
}

# Just to verify it got added:
$templateToExtend."__Base template"

然而,这并不能真正赋予 PowerShell 正义。它的强大之处在于,您现在可以将此代码段转换为可以通过管道传输的函数。您可以按照 Michael's tutorial on his blog 轻松完成此操作

关于powershell - 使用 Sitecore Powershell 将基本模板附加到模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18990973/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com