On Thu, Nov 13, 2008 at 2:05 PM, Sean McAfee <[EMAIL PROTECTED]> wrote:
> On Thu, Nov 13, 2008 at 10:58 AM, Todd Rinaldo <[EMAIL PROTECTED]> wrote:
>>
>> My question: Is there any easy way to make a recursive block that can
>> test if an unpredictably deep hash is defined?
>
> Perhaps, but it would be easier to write a routine in Perl:
>
> sub nested {
>   my ($hash, @keys) = @_;
>   for my $key (@keys) {
>     return if ref $hash ne 'HASH' || !exists $hash->{$key};
>     $hash = $hash->{$key};
>   }
>   return 1;
> }
>
> Provide the function to your template, and then you could say:
>
> [% NEXT IF !nested(hash, 'fi', 'fo', 'fum', 'bar') %]
>
> Alternately, you could make it a new hash vmethod.
>

Sean, a perl routine would be easier, but my restriction is my
inability to turn off {TOLERANT => 0, EVAL_PERL => 0}.

It sounds like the vmethod is the way to go, but I'm not clear how to
do that can you point me to where I could find an example?

_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to