tal:on-error
When any runtime error occurs while generating the element, the element will be replaced with result of
expression in the
tal:on-error
attribute.
Runtime errors are references to non-existent variables/paths/macros and any PHP exceptions thrown in the tag content.
<span tal:on-error="string:No username defined here" tal:content="user/name">the user name here</span>
If an error occurs accessing '
name
' or '
user
', the error string will be shown instead of the
<span>
element.
This also works on more than one level of template:
<span tal:on-error="string:error occurred somewhere"><span tal:content="user/firstname"/><span tal:content="user/lastname"/><span metal:use-macro="userMenu" /></span>
Due to optimizations performed by
PHPTAL,
tal:on-error
on element containing element with
metal:fill-slot
may not catch errors that happened inside the slot.