Zope
  Home arrow Zope arrow Page 4 - DTML Basics (part 3)
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
ZOPE

DTML Basics (part 3)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2002-07-02


    Table of Contents:
  • DTML Basics (part 3)
  • When In Rome...
  • A List In Time
  • An Easy Replacement
  • Bringing In The Database
  • Digging Deeper

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    DTML Basics (part 3) - An Easy Replacement
    ( Page 4 of 6 )

    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
     

       

    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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek