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

Ben*_*rds 4 powershell xpath sitecore

我是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;
Run Code Online (Sandbox Code Playgroud)

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

在此输入图像描述

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

Ada*_*icz 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"
Run Code Online (Sandbox Code Playgroud)

然而,这并没有真正让PowerShell正义.它的强大之处在于您现在可以将此片段转换为可以通过管道传输的功能.您可以在他的博客上按照Michael的教程轻松完成此操作

  • 你的意思是在Powershell?所有字段都以其存储形式公开.您可以通过使用$ item.FieldName来解决任何字段,或者如果它有一个空格$ _."字段名称"然后分配给.我认为只有日期不同,因为我将它们公开为DateTime对象.对Perl或Bash的好处是,您实际上使用的是实时Sitecore API而不是文本. (2认同)