Home arrow Zope arrow Page 4 - DTML Basics (part 3)

An Easy Replacement - Zope

Last time out, DTML Basics demonstrated conditional statements. This time around, it's time to study loops...which, in the DTML world, aren't exactly what you're used to. Take a look.

TABLE OF CONTENTS:
  1. DTML Basics (part 3)
  2. When In Rome...
  3. A List In Time
  4. An Easy Replacement
  5. Bringing In The Database
  6. Digging Deeper
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 5
July 02, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
How about a quick example to put all this in perspective? This next example allows you to replace the Zope management interface's folder listing with your own custom design, and also demonstrates how sequences can be used to do some fairly nifty things in Zope.

<table cellpadding="5" cellspacing="0" border="0"> <tr bgcolor="#CFCFCF"> <td><b>Type</b></td> <td><b>Name</b></td> <td><b>Size</b></td> <td><b>Last Modified</b></td> </tr> <dtml-in expr="objectValues()" sort="id" > <dtml-if sequence-even> <tr bgcolor="#DCDCDC"> <dtml-else> <tr> </dtml-if> <td><img src="<dtml-var sequence-var-icon>" border="0"></td> <td><a href="&dtml-absolute_url;"><dtml-var sequence-var-id></td> <td><dtml-var sequence-var-get_size> bytes</td> <td><dtml-var sequence-var-bobobase_modification_time></td> </tr> </dtml-in> </table>
And here's the output.



Isn't that neat? Just some manipulation to the sequence used in the previous example, along with some predefined variables, and you're ready to rock and roll.

<dtml-in expr="objectValues()" sort="id" > <dtml-if sequence-even> <tr bgcolor="#DCDCDC"> <dtml-else> <tr> </dtml-if>
First, I call the objectValues() method so that I have a sequence with the contents of the current folder. In this case, I've also added the "sort" attribute to the <dtml-in> tag - this allows me to specify the parameter by which sequence elements are to be sorted (the object ID).

The special "sequence-even" variable provides an easy way to implement alternating colours for the list elements - it's set to true if the value of the "sequence-index" variable is even. So the first element has a grey background and the next a white one. If you want to switch it around, you can use the "sequence-odd" variable, which works in the reverse direction.

<td><img src="<dtml-var sequence-var-icon>" border="0"></td> <td><a href="&dtml-absolute_url;"><dtml-var sequence-var-id></td> <td><dtml-var sequence-var-get_size> bytes</td> <td><dtml-var sequence-var-bobobase_modification_time></td>
The next section of the code is pretty straightforward- I've used various object properties to construct each row of the list:

"icon" - the path and name of the icon that is displayed along the object in the Zope listing

"id" - the object ID

"get_size" - the size of the object in bytes

"bobobase_modification_time" - the object's last modification time

Remember the "sort" attribute of the "dtml-in" tag? I told you that you could easily alter this attribute to manipulate the sorting order of the sequence. Here's how: set the value of this attribute to "icon", "get_size" or "bobobase_modification_time" and check the output; you'll see that the items in the listing get re-sorted against the named parameter.

 
 
>>> More Zope Articles          >>> More By Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

ZOPE ARTICLES

- Creating Zope Products
- Plone Content Types With Archetypes
- Flat User Management in Zope
- Creating Basic Zope Applications
- Getting started with Zope for Linux and Sola...
- ZPT Basics (part 4)
- ZPT Basics (part 3)
- ZPT Basics (part 2)
- ZPT Basics (part 1)
- Exception Handling In DTML
- DTML Basics (part 4)
- DTML Basics (part 3)
- DTML Basics (part 2)
- DTML Basics (part 1)
- Using Zope With Apache

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: