Conditional Statements

part of a tutorial on the Dynamic Publishing System by Karl Goldstein

The previous lesson illustrated how to deal with repetitive dynamic content. In cases where a list may have zero items, the template writer may want to display a special message to that effect. The template system provides a mechanism for dealing with such situations, where the appearance of the template must vary to suit the data.

Create the specification file

Create a file named state.data in a test directory of your server and enter the following specification:

View the data dictionary

Create the template

The template for this lesson illustrates a simple use of the if tag. The template tailors the output by checking the rowcount variable associated the users data source. This is a special variable that is always set when a query is performed.

There are alternate forms for the if tag parameters. The first form relies on a simple conditional syntax that is intended for general use by template authors. Global variables are referenced by enclosing their names in percent signs. Operators include eq, ne, gt, lt, ge, and le.

When a simple expression will not suffice, the second form accepts arbitrary Tcl code that is evaluated as as a conditional expression. For example:

<if eval="${lesson4.users.rowcount} == 0">

would produce equivalent results to the first if tag in the template listing above.

View results (state = CA)

View results (state = RI)

Tutorial Contents
karlg@arsdigita.com