4

私は 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 と呼ばれる 1 つのテンプレート アイテムで試してみたいだけです。これは $calloutTemplate のビューで、BaseTemplates セクションと Fields セクション (__Base テンプレートを含む必要があります) があることを示しています。

ここに画像の説明を入力

Sitecore の Powershell に解決策がない場合、Sitecore Rocks クエリ アナライザーの CRUD 操作は機能する可能性がありますか?

4

1 に答える 1

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 のブログのチュートリアルに従って簡単に実行できます。

于 2013-09-25T09:07:51.473 に答える