[Zope] ZPT and standard_error_message solution

Andy Dustman andy@dustman.net
25 Aug 2002 17:19:09 -0400


I ran into some problems using a ZPT for the standard_error_message, and
noticed from the archives that others had as well. It took me awhile but
I eventually found a cause and solution.

The problem occurs if your ZPT standard_error_message uses a template
macro, i.e.:

<html metal:use-macro="here/main_template/macros/master">

If the error is NotFound (404), then here apparently is nowhere, i.e.
not defined, and there the only way to directly acquire the template is
by using root, i.e.

<html metal:use-macro="root/main_template/macros/master">

(or something similar, depending on your template location)

Even then, here is (apparently) not defined within the template, so this
doesn't get you much if your template uses here, and it probably does.

Solution: Make standard_error_message a DTML method. It can be as simple
as:

<dtml-return expr="other_error_message(error_type=error_type,
error_message=error_message, error_value=error_value,
error_tb=error_tb)">

where other_error_message is a ZPT which uses a template. here is
defined (on a 404, here is the location of other_error_page). In my
case, I ended up using this instead:

<dtml-if "error_type=='NotFound'">
<dtml-return missing_error_message>
<dtml-else>
<dtml-return expr="other_error_message(error_type=error_type,
error_message=error_message, error_value=error_value,
error_tb=error_tb)">
</dtml-if>

The reason for this, I had trouble in the ZPT testing the error_type to
see if it was NotFound, and it was easier to test for this in the DTML
Method to use a different error page. You could do this with a Python
script as well, but you wouldn't gain much if anything.

-- 
Andy Dustman         PGP: 0x930B8AB6
    @       .net     http://dustman.net/andy
"Cogito, ergo sum." -- Rene Descartes
"I yam what I yam and that's all what I yam." -- Popeye