Zope
  Home arrow Zope arrow Page 4 - ZPT Basics (part 3)
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
     
     
    The Best Selling PC Migration Utility.
     
    ADVERTISEMENT

    Virtual Tradeshows by Ziff Davis Enterprise – A Unique Opportunity to Interact with IT Experts, Access Information, and Gain Insight on Today’s Trends in Technology Learn more

    ZPT Basics (part 3) - Sticks And Stones
    (Page 4 of 6 )

    ZPT also allows you to dynamically generate attributes and attribute values in a template, via the special "attributes" attribute (try saying that fast!). This TAL attribute makes it possible to dynamically assign values to HTML attributes, or to replace default attribute values with user-supplied ones.

    In order to illustrate, consider the following simple template (named "SticksAndStones"):

    <font tal:attributes="size request/size;color request/color; face request/face"> Sticks and stones will break my bones </font>
    In this case, the font face, colour and size will be dynamically set by ZPT based on values in the URL request. So, when you access this particular page with the following URL,

    http://localhost:8080/SticksAndStones?size=8&color=red&face=Arial
    here's what you'll see:



    If you take a look at the source code of the dynamically-generated page, you'll see that ZPT has used the values passed on the URL within the template, via the special "attributes" attribute, to dynamically generate HTML attributes for the <font> tag.

    You can also specify default values for your HTML attributes, and have ZPT replace them with user-defined ones if available. In order to illustrate this, consider the following rewrite of the previous example:

    <font color="blue" size="2" face="verdana" tal:attributes="color request/color | default; size request/size | default; face request/face | default"> Sticks and stones will break my bones </font>
    In this case, if I access the URL

    http://localhost:8080/SticksAndStones
    without sending it any input parameters, the template will use the default attributes of the <font> tag,



    whereas if I pass it specific values on the URL,

    http://localhost:8080/SticksAndStones?size=8&color=lime&face=Arial
    it will replace the default attribute values with the user-supplied values.



    Note my usage of the | conditional operator and the special "default" keyword, which tells ZPT to use the default value in case a user-supplied value is not available.

    Here's another example, this one demonstrating how the "attributes" attribute may be used in combination with a loop:

    <span tal:repeat="s python:1,2,3,4,5"> <font face="Verdana" tal:attributes="size s"> Sticks and stones will break my bones </font> <br> </span>
    In this case, the "repeat" attribute is used to iterate through a sequence of font sizes, with the "attributes" attribute used in each iteration to dynamically generate a new "size" attribute for the <font> tag. Here's the output:

    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

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway