[Templates] How To Throw Exception on Missing Method
Cees Hek
ceeshek@gmail.com
Thu, 26 Jul 2007 18:09:11 -0400
On 7/26/07, Matisse Enzer <menzer@apple.com> wrote:
>
> On Jul 25, 2007, at 8:36 PM, Bill Moseley wrote:
>
> > On Wed, Jul 25, 2007 at 01:30:46PM -0700, Matisse Enzer wrote:
> With DEBUG_UNDEF this template produces an error if someMethod()
> exists but
> returns and empty list:
>
> [% FOREACH thing IN object.someMethod %]
> [% thing %]
> [% END %]
>
> What I want is an error only if $object is undef, or if there is no
> someMethod() defined, and I want this behavior globally.
How about this:
[% IF object.can('someMethod') %]
[% FOREACH thing IN object.someMethod %]
[% thing %]
[% END %]
[% END %]
Cheers,
Cees