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

Handling Errors - 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 add primitive error-handling to your templates via the special "on-error" attribute, which allows you to specify a simple error message that is displayed when TAL encounters an error. Consider the following example:

<font color="red" size="2" face="verdana" tal:on-error="string:Form input error" tal:attributes="color request/color; size request/size; face request/face"> Sticks and stones will break my bones </font>
In this case, since my code requires the "size", "face" and "color" input variables to be specified as input parameters via the URL (notice that I have not used the "default" condition here, as I did in the previous example), an error will be generated if these variables are not present. However, rather than displaying the standard Zope error message,



I can intercept the error with TAL's "on-error" attribute, and replace it with my own, simpler error message.



"on-error" attributes are processed in a hierarchical manner, with TAL recursing upwards from the source of the error until it finds an "on-error" error handler. In the following example, even though the error is generated by the innermost <font> element, the error message generated comes from the outermost <div> element.

<div tal:on-error="string:Form input error"> <b><font color="red" size="2" face="verdana" tal:attributes="color request/color; size request/size; face request/face"> Sticks and stones will break my bones </font> </b> </div>
This is obviously a primitive example - you can do some pretty complex things with the "on-error" attribute. Take a look at http://www.zope.org/Wikis/DevSite/Projects/ZPT/RenderErrorHandlingStrategies for more information.

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