Enable field fallback functionality

Abstract

Add fallback functionality to fields in rendering variants

As well as the possibility to for sites, SXA lets you add fallback functionality to fields in rendering variants. Field fallback is the ability for a field's value to come from somewhere other than the field itself. This can be convenient when, for example, you have multiple titles on a page but not all of them are always filled in. Or, in a situation when you normally use your page title in navigation but in some cases this title is too long, and you want to specify a shorter title used explicitly for navigation.

To define the fallback:

  • Add a child item to a rendering variant field. You must define fallback items directly under the root of the rendering variant child items. Fallback items must not contain any child items.

For example, by default, the navigation component comes with a rendering variant that includes two fields for fallback:

Field

Description

SXA-fallback.PNG

NavigationTitle field.

SXA-fallback-second.PNG

The Title field is the first fallback item. If the NavigationTitle field does not exist or is left empty, the value from the Title field is taken.

SXA-fallback-third.PNG

The __Display Name field is the second fallback item. If the Title field does not exist or is left empty, the value from the __Display Name field is taken.

Note

Not all rendering variants have the same HTML hierarchy structure. For example, if you add a child item to section , this item defines new HTML that will be generated under the HTML tag selected in the section and will therefore not work as a fallback.

If the field name does not exist or is left empty, then all the child items of variant fields are fallback fields. However, if the field is editable (by default, all fields are editable), even if you have defined a fallback, in the Experience Editor, SXA will not perform fallback. Instead, you can edit the root field. This is because if the fallback was performed and the field was originally empty, there would be no way to provide the root field value. If you want fallback to be performed, you must always mark the field in the rendering variant as not editable.