我是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的视图,显示它有一个BaseTemplates部分和一个Fields部分(应该包含__Base模板):
如果Sitecore的Powershell中没有解决方案,Sitecore Rocks查询分析器CRUD操作是否可行?
答案 0 :(得分:6)
您正在寻找的脚本基本上是:
$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
之后轻松完成此操作