Language Fallback has always been a little tricky when using Glass.Mapper.Sc because it was necessary to use the VersionCountDisabler class. This was required because Glass.Mapper checks the number of version of an item in the requested language and returns null if there are no versions. The VersionCountDisabled stops this check from happening and returns a model using the empty Item that Sitecore returns allowing you to map shared fields to the model.

This has changed in Sitecore 8.1, the new Language Fallback features now mean that you no longer need to use the VersionCountDisabler.

For example lets take the following code running in Sitecore 8.1:

        protected void Page_Load(object sender, EventArgs e)
        {
            var sitecoreContext = new SitecoreContext();
            using (new VersionCountDisabler())
            {
                Model1 = sitecoreContext.GetCurrentItem<Model>();
            }

            Model2 = sitecoreContext.GetCurrentItem<Model>();

        }

In the watch window we can see that both the code in the VersionCountDisabler and outside return a Model:

We can also see in the watch window that the original language was english (the fallback language) and the requested language was Italian:

This is great news because now your Glass.Mapper solutions can become even simpler!


comments powered by Disqus