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>
© 2011 Shaun McCance
cc-by-sa 3.0 (us)

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.

As a special exception, the copyright holders give you permission to copy, modify, and distribute the example code contained in this document under the terms of your choosing, without restriction.

Powered by
Mallard