Language Fallback not working for Fields with Standard Values (Sitecore 8.1)

穿精又带淫゛_ 提交于 2019-12-12 10:13:20

问题


We had an issue where we enabled fallback language settings at the item level on a base template so that it would apply to all of our items. It worked for about 90% of our items but not for others even though the sitecore content editor indicated that it was working.

Placing this here for anyone else who has this issue. I didnt find a specific solution for this issue on Google and was lucky enough to figure it out. Hopefully this can help someone else out too.

Our setup is Sitecore 8.1 with Habitat Asp.net MVC


回答1:


Here are some steps to make language fallback work for all items by applying item level settings to a base template.

Step 1

First step to enable language fall-back is to set up the fall-back tree. We can build a hierarchical structure (or simple linear) for languages to fall back to Example:

In our case we would just do: EN-NZ --> EN

This is done /Sitecore/System/Languages by setting the fall-back language on each of the language nodes:

Step 2

Next we enable the language fall back feature for the site. At the deployed website locate the config file Sitecore.LanguageFallback.config And modify the config so that the following settings apply:

<setting name="LanguageFieldFallback.AllowVaryFallbackSettingsPerLanguage" value="true" />
…
<sites>
      <site name="shell">
        <patch:attribute name="enableItemLanguageFallback">true</patch:attribute>
        <patch:attribute name="enableFieldLanguageFallback">true</patch:attribute>
      </site>
      <site name="website">
        <patch:attribute name="enableItemLanguageFallback">true</patch:attribute>
        <patch:attribute name="enableFieldLanguageFallback">true</patch:attribute>
        <patch:attribute name="enforceVersionPresence">true</patch:attribute>
      </site>
    </sites>

Recycle the app pool

Step 3

Now the feature is enabled for the site we must enable the feature at the item level.

  1. Navigate to an item in the sitecore content editor and view the Advanced section
  2. If the Advanced section is not visible; select the View tab and check the Standard fields option
  3. Check the Enable Item Fallback option. (Displays item from fallback language if no language version exists )
  4. To restrict a page to a certain language, check the Enforce Version Presence option. In cases where a version is not found for a specific language, Sitecore's default behavior is to return an empty item. This happens when rendering an item or when trying to access it via Sitecore API. In cases where there’s no version available for the requested language, this option allows you to tell Sitecore NOT to return an item. This will end up redirecting the user to a 404 (not found) page, or returning NULL when trying to get the item via API.

We can apply these settings on the Standard Template and the setting will apply to all Items that inherit it

  1. Navigate to the Standard Template
  2. Create a Standard Values if does not exist
  3. Set the Enable Item Fallback option

This will get 90% of our items and fields working, however there is a caveat; this only works for fields that do not inherit their values from Standard Values.

You can easily identify these fields by viewing the Item in the content editor

This is something to do with how the Enable Item Fallback option is also inherited from Standard values of Standard Template and Sitecore won’t apply the setting to the fields that also inherit from standard values.

To handle fields/items in this scenario you do one of two things:

  1. Modify the field on the Item so that it does not inherit from standard values OR:
  2. Create a standard values on the Item template – It will inherit the Enable Item Fallback option from the Standard Values of the Standard Template
    1. Uncheck the option and Save
    2. Recheck the option and Save so that it no longer inherits the setting
    3. Now that the Enable Item Fallback option is not inherited it will apply. The fields on the item that inherit from standard values will now fallback and render

Note: I believe this is a bug because the content editor still displays the fields as inheriting their content from the fall back language when you change language however the content doesn’t render on the website until you do one of the methods mentioned above

Comments

  • There is also Field level settings to apply the same setting.
  • Also worth noting is that if you are having the issue above and apply the setting at the field level, it still won’t work until you do those steps above.



回答2:


I Faced a similar problem, and here it is why.

In my case I have a datasource template DChild who inherits from another datasource template DMother. Both DChild and DMother have standard values

When I created an item from DChild template, all fields whose values were been set by the standard values of DChild, were having their language fallback values coming from DMother standard values instead of the DChild standard value.

This was caused because the fallback was not enabled in the DChild Standard Values but was enabled in the DMother standard values.

Tricky huh ?



来源:https://stackoverflow.com/questions/39585520/language-fallback-not-working-for-fields-with-standard-values-sitecore-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!