Zope
  Home arrow Zope arrow Page 3 - ZPT Basics (part 3)
FaxWave - Free Trial.
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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? 
ZOPE

ZPT Basics (part 3)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2002-10-09

    Table of Contents:
  • ZPT Basics (part 3)
  • When In Rome...
  • Members Only
  • Sticks And Stones
  • Handling Errors
  • Endgame

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    PCmover - $15 Off with Coupon Code CJPH7Q

    ZPT Basics (part 3) - Members Only
    (Page 3 of 6 )

    You can also use the "repeat" attribute to hook your template up to a database, and dynamically generate output based on an SQL resultset. Consider the following example, which demonstrates how the "repeat" attribute can be used to iterate through a MySQL resultset and dynamically build a table containing elements of that resultset.

    <table cellpadding="5" cellspacing="0" border="1" width="250"> 
    <tr bgcolor="#CFCFCF"> 
    <td align="left"><b>User Details</b></td> 
    </tr>
    <tr tal:repeat="memberlist 
    here/SelectMembers"> 
    <td align="left"><font size="2"><b><span
    tal:replace="memberlist/fname">First 
    name here</span><span
    tal:replace="memberlist/lname">Last name here</span></b></font> 
    <br>
    <font size="1"><i tal:content="memberlist/tel">Telephone number 
    here</i>
    <br> <span tal:replace="memberlist/email">Email address
    here</span></font> 
    </tr> </table>
    
    In this example, SelectMembers is a ZSQL method used to retrieve a list of members from a database SELECT * FROM members as a sequence (for the uninitiated, a ZSQL Method is a special Zope object that allows you to communicate with a database). A ZPT loop iterates through it and prints the data as an HTML table.

    Here's what the output looks like:



    This example uses the "repeat" TAL attribute to loop over the result set returned by the SelectMembers ZSQL Method.

    <tr tal:repeat="memberlist here/SelectMembers">
    The TALES expression - "here/SelectMembers" - executes the ZSQL method. The rest of the code is good ol' HTML to make the page look pretty.

    More information on the "repeat" attribute can be found at http://www.zope.org/Wikis/DevSite/Projects/ZPT/RepeatVariable

    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-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway