Sitecore PowerShell script to enable Language fallback

Pranay
May 16, 2020  ยท  3691 views

A Sitecore PowerShell script to check if the selected sub tree of items have the language fallback enabled and update the items to enable the language fallback accordingly

Is this not the script you are looking for? Then check this complete list of Sitecore Powershell scripts

Check if language fallback enabled on an Item

The script is used to check an item and all its descendants if the language fallback is enabled. It lists all the items for which the language fallback is not enabled.

Fallback option

The script checks the value in the field ''__Enable Item Fallback'' for each item. This field value is '1' when the language fallback is enabled.

$sourcePath = "master:/sitecore/content/Home/Site1"
$items = Get-ChildItem -Path $sourcePath -Recurse
$rootItem = Get-Item -Path $sourcePath
$items = $items + $rootItem

foreach($item in $items){
    if ($item.Fields["__Enable Item Fallback"].Value -ne "1")
    {
        Write-Host $item.ID $item.Fields["__Enable Item Fallback"].Value $item.Paths.Path
    }
}

Script for updating an item to enable language fallback###

Say if you want to enable the language fallback of an item and all its descendants, then below scripts helps you. It checks each item if the fall back is enabled, if it is not then the script would update the item to enable the language fallback and publishes it. As the __Enable Item Fallback field is a shared field, it need not to be done on each language version separately.

$sourcePath = "master:/sitecore/content/Home/Site1"
$items = Get-ChildItem -Path $sourcePath -Recurse
$rootItem = Get-Item -Path $sourcePath
$items = $items + $rootItem

foreach($item in $items){

    if ($item.Fields["__Enable Item Fallback"].Value -ne "1")
    {
        $item.Editing.BeginEdit();
        $item.Fields["__Enable Item Fallback"].Value = '1'
        $item.Editing.EndEdit();
        Write-Host $item.ID $item.Fields["__Enable Item Fallback"].Value $item.Paths.Path
    }
 
}

LanguageFallback

Hope this helps you. Please comment your thoughts.

AUTHOR

Pranay

A Software Engineer by profession, a part time blogger and an enthusiast programmer. You can find more about me here.


Post a comment




Thank you! You are now subscribed.

Sign up for our newsletter

Subscribe to receive updates on our latest posts.

Thank you! You are now subscribed.