I have a menu container that contains link items. The menu container is just a container so it does not need to have separate versions in all the active site languages. More specifically, it will always only contain a version in english. The childitems however need to have separate versions in the active languages and there should be no language fallback if an item does not have a version in a language.

The code:

var mainMenuContainer = menuContainer.Children.FirstOrDefault(ch => ch.Name == MAINMENU_ITEMNAME);

So the mainMenuContainer will have the english language.

Then I do:

    var mainNavItems = mainMenuContainer.Children.Where(m => m.TemplateID == Constants.LinkItemTemplateId); 

How could I enforce that this call only returns child items that have a version in the context language? Maybe I could do something like

 foreach (var language in item.Languages)
     var langSpecificItem = MasterDb.GetItem(item.ID, language);

     if (langSpecificItem.HasVersion())


but this seems not to be a terribly efficient way. I see that I could also check the IsFallback property of each item, but that seems not to be very elegant.

1 Answer 1

var mainNavItems = mainMenuContainer.Children.Where(m => m.TemplateID == Constants.LinkItemTemplateId && m.Versions.Count > 0); 

Where: m.Versions.Count > 0 is the new bit.

Items don't have language versions, only field values do. Add the above to your LINQ expression and you're good to go.

There is a new functionality, EnforceVersionPresence that also does this on a data layer level - but I highly recommend you do not use it. You'll basically have to "break off" your API from standard implementations to "Enforced" which could make it less portable.

  • If I add the m.Versions.Count clause, I still get the fallback items. The strange thing is that the language of the item returned is non-english for which there is no version in sitecore but item.Version.Count = 1 for the returned item. So the .Version.Count is read from the fallback item, it seems..
    – staccata
    Aug 2, 2018 at 9:25
  • Oh so you ARE using fallbacks?
    – Mark Cassidy
    Aug 2, 2018 at 9:58
  • Yes, I have enableItemLanguageFallback=true for the website. But I do want to override this behaviour.
    – staccata
    Aug 2, 2018 at 10:54

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.