TALES cancellation

Sometimes it is desirable within a TAL attribute to 'break out of' the current action and abort whatever was happening. For example, if a tal:content attribute were filling in the current user's username but no user were logged in - the current user object might be null. Cancellation would allow the TAL content operation to be aborted, leaving the hard-coded HTML content of the element in place.

One way of handling this and avoiding an error would be to abort the content attribute altogether. This may be performed in a TALES path: expression by providing multiple paths within the expression.

Different TAL attributes react differently to action cancellation.

Any expression result may cancel the action. In order to do so, the expression result should be an object which implements CSF.Zpt.Rendering.IActionCanceller. If the result returns true for the method ShouldCancelAction() (which is defined by that interface), then it will cancel the TAL action. You may also use the built-in root variable default.

Example

Consider the following:

<p tal:define="currentUser Model/CurrentUser">
  You are logged in as
  <span tal:content="currentUser/Name | default">an unknown user</span>.
</p>

This is very similar to the example provided for providing multiple paths to an expression, except that the fall-back value is the built-in root variable default. This would cause the content attribute to be aborted, and for the existing content of the span element not to be replaced. In this case, that provides us with our fall-back content.