Fallback Behavior

Mallard Conditionals is an extension to the core Mallard vocabulary. Not all Mallard processing tools will support all extensions. Mallard has well-defined rules for how to handle unknown extension elements and attributes. This page provides examples for how Conditionals elements will be handled by processing tools that do not support this extension.

In Mallard, unknown attributes are ignored. When you use the if:test attribute on any block element or list item, a non-supporting tool will ignore the attribute and display the element unconditionally. The following is always shown by a non-supporting tool:

<p if:test="target:html">YES</p>

The if:if and if:choose elements occur in block context. When a processing tool encounters an unknown element in block context, it processes the children in restricted block context. In restricted block context, unknown elements are ignored.

If you use an if:if element with simple block content, such as a paragraph, a non-supporting tool will always display the content.

<if:if test="target:html">
  <p>YES</p>
</if:if>

If, however, you nest an if:if element in an if:if element, the inner element will be processed in restricted block context, so it will not be shown. You can use this to hide content from a non-supporting tool, for example by repeating the same condition.

<if:if test="target:html">
  <if:if test="target:html">
    <p>NO</p>
  </if:if>
</if:if>

Because if:when elements are always children of if:choose elements, non-supporting tools will always process them in restricted block context, so they will not be displayed. The same is true for if:else elements.

<if:choose>
  <if:when test="target:html">
    <p>NO</p>
  </if:when>
  <if:else>
    <p>NO</p>
  </if:else>
</if:choose>

This specification allows two different ways to provide fallback content for if:choose elements. Instead of using an if:else element, you can put fallback block content directly in the if:choose element. Supporting tools will treat this exactly as if you had used an if:else element, but non-supporting tools will show this fallback content.

<if:choose>
  <if:when test="target:html">
    <p>NO</p>
  </if:when>
  <p>YES</p>
</if:choose>