Zope
  Home arrow Zope arrow Page 3 - 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) - A List In Time
    ( Page 3 of 6 )

    The example you just saw used a simple sequence. However, you can also loop over a collection of objects using the same technique. Take a look at a simple example that lists the objects in the current folder (use a DTML Method here instead of a DTML Document).

    This folder contains: <ul><dtml-in expr="objectIds()"> <li><dtml-var sequence-item></li> </dtml-in> </ul>
    Here's the output:

    This folder contains: * ifOnly * access * selectDay * SampleSequence * WithOrWithoutYou
    Over here, I've used the ObjectIds() method of the ObjectManager class to produce a list of objects, and iterated through that list using a DTML loop. For the uninitiated, the ObjectManager class is a class that contains other Zope objects; it provides methods that allow you to find out about the objects it "manages".

    Let's replace ObjectIds() with ObjectValues(), in order to make things a little more interesting.

    <dtml-in expr="objectValues()"> <dtml-if sequence-start><b>There are <dtml-var sequence-length> items in this folder.</b><br></dtml-if> This is <dtml-var sequence-var-id>. <br> <dtml-var sequence-item><p> </dtml-in>
    Check the output and get ready for a big surprise.



    How did this happen? Well, the ObjectValues() method returns the objects present in the folder. So, when I reference each item with the "sequence-item" variable, I'm actually accessing the object itself, and displaying the output of the DTML code that is present in the object.

    Once again, the "sequence-length" variable has been used to display the number of objects in the current folder. But how was I able to display the ID of the object at the beginning of each listing?

    This is another feature available with sequences: you can access all the variables associated with an object using the following syntax:

    sequence-var-varname
    where varname is the name of the variable whose value you want to display. So, you can access the title using "sequence-var-title" or the object ID using "sequence-var-id", just as in the example above.

    And here's another variant of the example above:

    <dtml-in expr="objectItems()"> This is <dtml-var sequence-key> <br> <dtml-var sequence-item> <p> </dtml-in>
    The output is the same as that of the previous example. However, over here, I've used the ObjectItems() method of the Object Manager. This returns the objects in the form of a tuple (a container variable, which can contain one or more values, kinda like an associative array or hash). The ObjectItems() method returns the IDs and the objects as key-value pairs, so you can access the name of the object by using the "sequence-key" variable and the object itself using the "sequence-item" variable.

     
     
    >>> 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