UNPKG

zpt

Version:

Zenon Page Templates - JS (ZPT-JS)

97 lines (84 loc) 4.38 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>ZPT-JS reference - Attributes - TALOnError</title> <script type="module" src="../js/zpt.js"></script> <script type="text/javascript" src="../lib/syntaxHighlighter/lib.js"></script> <link rel="stylesheet" type="text/css" href="../docs.css"> <link rel="stylesheet" type="text/css" href="../lib/syntaxHighlighter/theme.css"> </head> <body> <div data-use-macro="'page@templates.html'"> <div data-fill-slot="'page-header'"> <h1>ZPT-JS reference - Attributes - TALOnError</h1> <ul> <li><a href="#syntax">Syntax</a>.</li> <li><a href="#description">Description</a>.</li> <li><a href="#differences">Differences with ZPT</a>.</li> <li><a href="#examples">Examples</a>.</li> </ul> </div> <article data-fill-slot="'article'"> <h2 data-attributes="id 'syntax'">Syntax</h2> <pre class="syntax"> argument ::= ('structure') expression </pre> <h2 data-attributes="id 'description'">Description</h2> <p> The <em>data-on-error</em> statement provides error handling for your template. When a TAL statement produces an error, the TAL interpreter searches for a <em>data-on-error</em> statement on the same element, then on the enclosing element, and so forth. The first <em>data-on-error</em> found is invoked. It is treated as a <em>data-content</em> statement. </p> <p> A local variable error is set. This variable has these attributes: </p> <ul> <li><em>type</em>. The exception type.</li> <li><em>value</em>. The exception instance.</li> <li><em>traceback</em>. The traceback object.</li> </ul> <p> The simplest sort of <em>data-on-error</em> statement has a literal error string or <code>nothing</code> 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. </p> <p> Note: extracted from <a href="https://zope.readthedocs.io/en/latest/zopebook/AppendixC.html#on-error-handle-errors">Zope Page Templates Reference</a>. </p> <h2 data-attributes="id 'differences'">Differences with ZPT</h2> <ul> <li> <em>text</em> prefix not supported but not needed, it is the default behaviour. </li> </ul> <h2 data-attributes="id 'examples'">Examples</h2> <p> Simple error message: </p> <pre class="brush: html"> &lt;div data-on-error="'Error trying to get user name!'" data-content="myObject/getUsername()"&gt; Ishmael &lt;/div&gt; </pre> <p> Removing elements with errors: </p> <pre class="brush: html"> &lt;div data-on-error="nothing" data-content="myObject/getUsername()"&gt; Ishmael &lt;/div&gt; </pre> <p> Calling an error-handling script (it returns html code): </p> <pre class="brush: html"> &lt;div data-on-error="structure myObject/errorScript()"&gt; ... &lt;/div&gt; </pre> <p> Note: extracted from <a href="https://zope.readthedocs.io/en/latest/zopebook/AppendixC.html#on-error-handle-errors">Zope Page Templates Reference</a>. </p> </article> </div> </body> </html>