1

I'm using Glass 5.4.18 with Sitecore 9.0.2. I have a base template for my site that has language fallback turned on by default, but for a few items the client wants to disable language fallback so the item does not appear in certain languages.

I've gone into the individual item in a navigation tree and unchecked Enable Language Fallback, and I've tried this both with and without Enforce Version Presence checked on. But when I retrieve the item in my controller as follows:

IGlassBase testGlass = _mvcContext.SitecoreService.GetItem<IGlassBase>(new Guid("{5D70191B-546B-4902-B764-175F2C4FE6DB}"));

The "testGlass" variable is not null like I'd expect it to be. I get the item details back, but if I check the actual item (either through a Glass property marked with the SitecoreItem attribute, or using the Sitecore API directly) I see the Versions.Count is 0 as I'd expect.

A lot of the prior answers on this topic appear to be from Glass 4 or when language fallback was first introduced, and mention using a VersionCountDisabler. I didn't think any extra wiring was necessary at this stage, but my direct query and looping past them item in a SitecoreChildren iteration yield the item to display in my navigation tree incorrectly.

I feel like I'm missing a setting, but I can't find what it might be, if there's a configuration or script I need to add in. I could do a .Where and look for Versions.Count > 0 but that seems excessive.

  • To confirm, when you say you "checked Enforce Version Presence" on/off.. did you go through all steps mentioned here? ctor.io/… – jrap May 16 at 18:11
  • @jrap You win the kewpie doll...to collect your prize, please put this in as an answer. I'm so used to adding the enableLanguageFallback site setting that I missed the needed one for enforceVersionPresence. Thanks much! – Ken McAndrew May 16 at 19:01
  • Hah, thanks, will do. – jrap May 16 at 19:04
3

This is not a glass mapper issue, but instead a miss on the full Enforce Language Presence implementation.

Per Sitecore documentation:

1) Enable the enforceVersionPresence attribute

This attribute is applicable to a <site> definition element. Patch it in appropriately.

<site name="mysite">
  <patch:attribute name="enforceVersionPresence">true</patch:attribute>
</site>

Note: Do not patch this into the shell site definition.

2) Enforce version presence on your template

To enable enforce version presence on an item or a data template:

In the Content Editor, navigate to the relevant item or template, in the Advanced section, select Enforce Version Presence.

Note:

You can also enable this on a base template to allow data templates to inherit the setting from there.

  • The link I referenced in my comment specified to include this attribute on the "shell" site, but Sitecore documentation specifically says to NOT do this. – jrap May 16 at 19:15
  • 1
    Yeah, I found that out by doing, I noticed by setting it up on "shell" you only see the languages in the dropdown you have content for. Thank you very much for the help! – Ken McAndrew May 16 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.