Home arrow Zope arrow Page 3 - ZPT Basics (part 3)

Members Only - Zope

Now that you've got the skinny on variables and conditional statements, expand your knowledge of the ZPT universe with this discussion of TAL loops, dynamically-generated attributes and error handlers.

TABLE OF CONTENTS:
  1. ZPT Basics (part 3)
  2. When In Rome...
  3. Members Only
  4. Sticks And Stones
  5. Handling Errors
  6. Endgame
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 9
October 09, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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
 

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: