Add a basic template to a template using Sitecore Powershell

I am new to Sitecore PowerShell (and PowerShell in general), and I would like to create a script that will add a template as a base template to the list of ChildItem templates in a specific context folder.

Since the __Base pattern is a standard value, not a regular field, I'm not sure if there is syntax available to add a GUID to the multilist field that it uses (restricted channel).

Here is what I tried

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

I can get all the recursive data with Get-ChildItem -recursive, but for a test run, I just want to try it on one element of the template called Callout. Here is a view of $ calloutTemplate showing that it has a BaseTemplates section and a Fields section (which should include the __Base template):

enter image description here

If there is no solution in PowerShell for Sitecore, can the Sitecore Rocks Query CRUD statement work?

+4
source share
1 answer

Basically the script you are looking for is:

 $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 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" 

However, this does not give justice to PowerShell. The strength of this is that now you can turn this fragment into a function that you can enter. You can do it easily by following Michael on your blog.

+6
source

All Articles