1

We are building a multilingual site and language fallback is enabled for all the languages to fall back to English language content. Though one exception is that, we don't want pages of a specific template on one of the language sites to fallback to English Language. My requirements are very similar to this post Disable Language Fallback for specific item language As per the answer in that post, using "Enforce Version Presence - Hide this item if no language version exists [shared]" settings, it disables the language fallback for all the language site. So it doesn't meet our requirement. So How can I achieve disabling fallback on a specific template for a given language?

1 Answer 1

1

What you can do is patch the GetLanguageFallbackItem processor in the GetLanguageFallbackItem pipeline and check for your custom requirements:

public class CustomGetLanguageFallbackItem : Sitecore.Pipelines.ItemProvider.GetItem.GetLanguageFallbackItem
{
    public override void Process(GetItemArgs args)
    {
        var item = args.Database.GetItem(args.ItemId);
        if (item != null && Sitecore.Context.Site != null)
        {
            // Check for custom requirements
            if (Sitecore.Context.Site.Name == "site-with-disabled-fallback" 
                && item.TemplateID == new ID("MY-TEMPLATE-GUID"))
            {
                return; // abort processor to disable fallback
            }
        }

        // Proceed with fallback processor
        base.Process(args);
    }
}

Config patch:

 <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <group name="itemProvider" groupName="itemProvider">
        <pipelines>
          <getItem >
            <processor type="My.Namespace.CustomGetLanguageFallbackItem, My.Namespace" 
                       patch:replace="Sitecore.Pipelines.ItemProvider.GetItem.GetLanguageFallbackItem, Sitecore.Kernel"/>
          </getItem>
        </pipelines>
      </group>
    </pipelines>
  </sitecore>
</configuration>

Note: this has not been tested thoroughly. Please leave comment if it works for you.

2
  • Thanks Mark for the feedback and potential solution. I will try it out and inform if it works. (though i may not be able get back this week).
    – Dinesh
    Nov 4, 2019 at 4:01
  • 1
    Using line below will cause infinite loop var item = args.Database.GetItem(args.ItemId); You might need to use code below instead: var item = args.Result ?? ((object)args.ItemId != null ? args.FallbackProvider.GetItem(args.ItemId, args.Language, args.Version, args.Database, args.SecurityCheck) : args.FallbackProvider.GetItem(args.ItemPath, args.Language, args.Version, args.Database, args.SecurityCheck)); Jun 14, 2023 at 9:17

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.