Previous Chapter | Next Chapter | Up | Next Section | Contents
Iterative Insertion, the dtml-in Tag
Commonly, it is necessary to insert a sequence of values. Some objects, like
Zope
SQL
Method
s, and
Confera
Topics
support searching and a means is needed for iterating over search results.
When creating input forms with select lists, it is sometimes a good idea to store the contents of the list in a folder property so that the list can be edited independently from the input form. In this case, the select list options are inserted into a form by iterating over the list property.
The
dtml-in
tag is used to iterate over a sequence of objects. For example, an employee directory listing might be created with DTML source like that shown in figure 2. In this example,
employees
is either a sequence of employees, or a function, such as an
Zope SQL Method
, that computes a sequence of employees. Each employee has a
name
and
phone
attribute. These attributes are accessed using dtml-
var
tags. An dtml-
in
tag's
sort
attribute is used to sort employees by name in the output. The
dtml-in
tag attributes are listed in table 18.
<table>
<tr><th>Name</th><th>Phone number</th></tr>
<dtml-in employees sort=name>
<tr>
<td><dtml-var name></td>
<td><dtml-var phone></td>
</tr>
</dtml-in>
</table>
|
dtml-in
tag attributes
Name
|
Needs an argument
|
Description
|
name
|
yes
|
Insert the name of the variable. See "The name attribute".
|
expr
|
yes
|
Insert an expression that evaluates the value. See The expr attribute".
|
mapping
|
no
|
Normally, the attributes of items in the sequence are displayed. But, some items should be treated as mapping objects, meaning that the items are to be looked up.
|
sort
|
yes
|
The sort attribute is used to cause a sequence of objects to be sorted before text insertion is performed. The attribute value is the name of the attribute (or key if the mapping attribute was provided) that items should be sorted on.
|
start
|
yes
|
The name of a (request) variable that specifies the number of the row on which to start a batch.
|
size
|
yes
|
The batch size.
|
skip_unauthorized
|
no
|
Use of this attribute causes items to be skipped if access to the item is unauthorized. See "Access Control". If this attribute is not used, then Unauthorized errors are raised if unauthorized items are encountered.
|
orphan
|
yes
|
The desired minimum batch size.
|
overlap
|
yes
|
The number of rows to overlap between batches.
|
previous
|
no
|
If the previous attribute is included, then iterative insertion will not be performed. The text following the
in
tag will be inserted and batch processing variables associated with information about a previous batch will be made available.
|
reverse
|
no
|
Used with the sort attribute, objects can be sorted in reverse order.
|
next
|
no
|
The next attribute has the same meaning and use as the previous attribute except that variables associated with the next batch are provided.
|
In the example, an empty table would be displayed if there were no employees. To avoid displaying an empty table a message can be provided indicating that there are no employee by using the
in
tag in combination with the
dtml-if
tag, as shown in figure 3. In figure 3, the
dtml-if
tag is used with the
employees
variable. Sequences of objects are false if they are empty and true if they are not. If there are no employees, the condition in the
dtml-if
tag is false and the text following the
dtml-else
tag is inserted.
<dtml-if employees>
<table>
<tr><th>Name</th><th>Phone number</th></tr>
<dtml-in employees sort=name reverse>
<tr>
<td><dtml-var name></td>
<td><dtml-var phone></td>
</tr>
</dtml-in>
</table>
<dtml-else>
Sorry, there are no employees.
</dtml-if>
|
Previous Chapter | Next Chapter | Up | Next Section | Contents
SUBSECTIONS