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

August 08, 2022
Sitecore Item/Field Fallback Script and Configuration
Mitesh Patel
Mitesh Patel
Technical Head
sitecore-item-field-fallback-script-and-configuration

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

In our latest upgrade project, the version 7.2 field fallback module was used so when we started the upgradation, we found a lot of dependency. We faced challenges for upgradation whereas in the versions 9 and 10, we were able to use the inbuilt fallback features.

In order to use the language fallback, you need to enable either the item-level or the field-level fallback on the relevant sites, items, fields or templates.

In addition to that, on the relevant language definition items, you have to specify the fallback language that determines which version of an item or field is there that 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.


YOU MAY ALSO LIKE