On Thu, Nov 13, 2008 at 2:42 PM, Josh Rosenbaum <[EMAIL PROTECTED]> wrote:
> Todd Rinaldo wrote:
>>
>> What we discovered we need to do is this
>> defined fee && fee.defined('fi') && fee.fi.defined('fo') &&
>> fee.fi.fo.defined('fum')
>>
>> To make things more dificult, the length of the nest isn't always the
>> same. For instance, we might need to test if fee.fi.fo.fum.foo.bar is
>> defined.
>>
>> My question: Is there any easy way to make a recursive block that can
>> test if an unpredictably deep hash is defined?
>
> Ok, I don't really have a good picture of your exact situation and you may
> have already thought of this since it seems pretty simple. I'll throw it out
> there anyway.
>
> *) You might be able to simplify that .defined() stuff. You don't need to
> use the defined test until the very last item:
>
> [% IF a.b.c.d.e && a.b.c.d.e.defined('f') %]
>
> *) If necessary, you could always use a WHILE statement to traverse through.
> That in combination with the following could help.
>
> *) You could also create a BLOCK that will output a value if your conditions
> are true.
>
> [% a = PROCESS my_test_block %]
> [% IF a %]do stuff [% END %]
> [% BLOCK my_test_block %]do test here that will output something if
> correct[% END %]


The key thing here is that design decisions have made us choose the
following 2 options:  {TOLERANT => 0, EVAL_PERL => 0}.
NOTE: We're not using Template for webpage rendering here.

[% IF defined a.b.c.d %] fails with the above features on if a,b,c or
d are not defined as part of the structure.

I'm unclear how I could write a block to test if a.b.c....z are
defined where there could be an unpredictable number of letters
between a and z. I was hoping someone might know this.

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

Reply via email to