Previous Chapter | Next Chapter | Up | Next Section | Contents

Conditional Insertion, the if and unless Tags


Occasionally, the text to be included in a document is dependent upon some data. The if tag is provided to support the conditional insertion of text based on DTML variables or expressions. As described in See DTML Tag Syntax, the if tag has four forms:

  1. An if tag, with a closing /if tag,
  2. An if tag with an else tag and a closing /if tag.
  3. An if tag with one or more elif tags, an else tag, and a closing /if tag, and
  4. An if tag with one or more elif tags, no else tag, and a closing /if tag.

The if tag works in a straightforward manner. The variable or expression given in the if tag is evaluated. If the variable or expression value is true12, then the text following the if tag is inserted. If the variable or expression value is false, then for each elif tag given, the variable or expression given in the elif tag is evaluated. If an elif variable or expression value is true, the text following the elif tag is inserted and none of the following elif variables or expressions are evaluated. If there are no elif tags or if all of the elif tag variable or expression values are false, then the text following the else tag is inserted. If no else tag was supplied, then no text is inserted.

The if and elif tags support only the standard name and expr attributes. The else tag accepts no attributes.

In addition to the if tag, the unless tag is provided with its associated closing tag, /unless, to insert text if a condition is false. Like the if tag, the unless tag accepts the standard name and expr attributes:

<!--#unless input_name-->
You did not provide a name.
<!--#/unless-->

Previous Chapter | Next Chapter | Up | Next Section | Contents