ZPT-JS reference - Attributes - TALOnError

Syntax

argument ::= ('structure') expression
                

Description

The data-on-error statement provides error handling for your template. When a TAL statement produces an error, the TAL interpreter searches for a data-on-error statement on the same element, then on the enclosing element, and so forth. The first data-on-error found is invoked. It is treated as a data-content statement.

A local variable error is set. This variable has these attributes:

The simplest sort of data-on-error statement has a literal error string or nothing for an expression. A more complex handler may call a script that examines the error and either emits error text or raises an exception to propagate the error outwards.

Note: extracted from Zope Page Templates Reference.

Differences with ZPT

Examples

Simple error message:

                    <div data-on-error="'Error trying to get user name!'"
                         data-content="myObject/getUsername()">
                        Ishmael
                    </div>
                

Removing elements with errors:

                    <div data-on-error="nothing"
                         data-content="myObject/getUsername()">
                        Ishmael
                    </div>
                

Calling an error-handling script (it returns html code):

                    <div data-on-error="structure myObject/errorScript()">
                    ...
                    </div>
                

Note: extracted from Zope Page Templates Reference.