This attribute replaces the element with the tal:on-error content if any runtime error is detected while generating the element, such as reference to non-existent variable or macro.

<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 at the tag's place.

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" />


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.