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

标签 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;

我可以使用 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/

相关文章:

powershell - 批处理文件下载并一次运行多个文件?

powershell - PowerShell 中的特殊字符 "!"是什么意思?

selenium - 具有相同类型和 ID 的多个按钮

sitecore - 模板标准值的布局详细信息的继承

Sitecore - 在 zip 文件中上传两个名称相同但扩展名不同的文件

powershell - 如何在 Powershell 中安装 Mailkit

.net - 通过 SetSecurityDescriptor 设置 WMI ACL

python - 使用 lxml 解析 xml - 提取元素值

XPath 查找在 PhantomJS 中不起作用

pdf - 在 Sitecore 多站点安装上提供 pdf 文档时如何更改网站图标