Let’s Talk

We would love to hear from you. Want to know more about
our services or have any questions? Say Hi!

Sitecore Item/Field Fallback Script and Configuration

author-icon-1 Mitesh Patel

category-icon Sitecore Training

Sitecore provides an awesome field back functionality to manage the fallback for multi-language websites. In the previous Sitecore version, 7.2 we needed to install the field fallback module as a separate module but now in Sitecore 9 and 10 versions, we have inbuilt functionality to manage the fallback activity.

In our last upgrade project, Sitecore 7.2 version field fallback module was used. So, when we started upgradation, we found lots of dependency in that module. We faced many challenges for upgradation in that module. In the 9 and 10 versions, we used Sitecore inbuilt fallback features.

To use the language fallback, you have to enable either item-level or field-level fallback on the relevant sites and the relevant items, fields, or templates.

In addition, on the relevant language definition items, you specify the fallback language that determines which language version of an item or field you want displayed when there is no version available in the current language.

To enable site-level fallback, you have to add the below configuration in the config file

                                 <patch:attribute name="enableItemLanguageFallback">true</patch:attribute> 
                                 <patch:attribute name="enableFieldLanguageFallback">true</patch:attribute> 
                            

But when we upgrade the project, templates are already created so we have to manually or automatically enable item and field level fallbacks. Please refer to the below PowerShell script for the automatically enabled field and item-level fallbacks.

Please refer to the below script for enabling item and field level fallbacks:

Below I have mentioned the PowerShell script for enabling field fallback in Sitecore. While you run the script it would target the particular template node and it would check the field fallback and item fallback checkboxes in template items and enable field fallback functionality for items which are created based on those templates.

Item level language fallback script:

                                
$sourcePath = "web:/sitecore/templates/project/ABC" 

$items = Get-ChildItem -Path $sourcePath -Recurse 

$rootItem = Get-Item -Path $sourcePath 

$items = $items + $rootItem 

 

foreach($item in $items){ 

 

     Write-Host $item.ID $item.Name 

 

    if ( $null -ne $item.Fields["__Enable Item Fallback"] -and $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 

    } 

} 
                                
					        
sitecore-item-field-fallback-script-and-configuration-1

Field level language fallback:

                                
$sourcePath = "web:/sitecore/templates/project/Blog" 

$items = Get-ChildItem -Path $sourcePath -Recurse 

$rootItem = Get-Item -Path $sourcePath 

$items = $items + $rootItem 

 

foreach($item in $items){ 

 

     Write-Host $item.ID $item.Name 

 

    if ( $null -ne $item.Fields["Enable Shared Language Fallback"] -and $item.Fields["Enable Shared Language Fallback"].Value -ne "1") 

    { 

        $item.Editing.BeginEdit(); 

        $item.Fields['Enable Shared Language Fallback'].Value = '1' 

        $item.Editing.EndEdit(); 

        Write-Host $item.ID $item.Fields["Enable Shared Language Fallback"].Value $item.Paths.Path 

    } 

} 
                                
                            
sitecore-item-field-fallback-script-and-configuration-2

Once you performed the above script in Sitecore, now language field fallback checkbox is ticked and your fallback functionality will work smoothly.

Recent Posts