4

I am trying to remove a base template if found and add a different base template if not found. In the code below the standard template is never found even though I know its there. Is it because I'm trying to find the template on a template? Should I use descendants somehow? I've commented the remove and add for now...

$baseL = Get-Item -Path "master:\sitecore\Templates\Toro\Foundation\Language\_Language Fallback";
$baseS = Get-Item -Path "master:\sitecore\templates\System\Templates\Standard template";

cd master:\Templates\Toro\Feature\;

Get-ChildItem -recurse | ForEach-Object {

    if ($_.TemplateName -eq 'Template') {

        # Get the direct template for the item, then check to see if it has a certain base template based on the template's ID
        $hasSTemplate = [Sitecore.Data.Managers.TemplateManager]::GetTemplate($_).InheritsFrom($baseS.ID);

        # Remove Standard Template
        if ($hasSTemplate) {
            echo "Yep, it has that template."
            #Remove-BaseTemplate -Path "master:/sitecore/content/User Defined/Page" -TemplateItem @($baseS)
        }

         # Get the direct template for the item, then check to see if it has a certain base template based on the template's ID
        $hasLTemplate = [Sitecore.Data.Managers.TemplateManager]::GetTemplate($_).InheritsFrom($baseL.ID);

        # Add Language Template
        if ($hasLTemplate –eq $FALSE) {
            echo "Yep, it does not have that template."
            #Add-BaseTemplate -Path "master:/sitecore/content/User Defined/Page" -TemplateItem @($baseL)
        }

        Write-Host $_.FullPath
    }
};

1 Answer 1

2

I imagine you are headed in the right direction when it comes to adding and removing base templates. You can use this command to help you determine when items are referring to a given template.

# Id references the Standard Template
Get-Item -Path "master:{1930BBEB-7805-471A-A3BE-4858AC7CF696}" | Get-ItemReferrer

Referencing Standard Template

If one of your user defined templates inherits from the specified template you will know it through the above query.

Is the Standard Template causing an issue with your templates?

1
  • No - I just need to replace it with the language fallback template which intern inherits from the standard.
    – M. Brandel
    Commented Jan 26, 2018 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.