[MTOS-dev] testing var for empty before using in mt:loop

Jay Allen jay at endevver.com
Fri May 2 18:50:49 PDT 2008


I just wanted to reply to this both to thank Beau for posting it AND  
to make sure you all get another chance to see it.  The second example  
Beau provides is, I think, one of the hands down coolest little tricks  
and by-product of iterative loop tags and conditional tags two  
different sides of the same coin.  It's also a construct that I would  
be very few people know about.

--
Jay Allen
Endevver Consulting
415-200-6985



On May 1, 2008, at 5:35 PM, Beau Smith wrote:
> Steve_
>
> Here are two examples that will work if foo_loops is null or "" or  
> 0....
>
> ------------
>
> <mt:if name="foo_loops">
>     <mt:loop name="foo_loops">
>         ...
>     </mt:loop>
> <mt:else>
>     zero-state message here
> </mt:if>
>
> ------------
>
> <mt:loop name="foo_loops">
>     ...
> <mt:else>
>     zero-state message here
> </mt:loop>
>
> ------------
>
>
> _beau
>
>
>
>
> On May 1, 2008, at 3:39 PM, Steve Ivy wrote:
>> In this case, the code does a lookup of "all URIs for this Friend"  
>> and
>> assigns it to a param. It may be empty. In the tmpl, I want to show a
>> "No URIs" message instead of dropping into the loop if uris has no
>> entries.
>>
>> On Thu, May 1, 2008 at 3:34 PM, Timothy Appnel <tim at appnel.com>  
>> wrote:
>>> Meaning null or '' or 0? Yes. Meaning an array refeence with zero
>>> elements? No. Not with mt:if in that position though I think the  
>>> loop
>>> would never start if coo_loops was a reference to an empty array
>>> reference.
>>>
>>> Anyway, the mt:if statement and others follows the standard Perl
>>> evaluation of true and false values. Null, '' (blank string) or 0
>>> (zero) is false and everything else is true.
>>>
>>>
>>>
>>> <tim/>
>>>
>>> --
>>> Timothy Appnel
>>> Appnel Solutions
>>> http://appnel.com/
>>>
>>
>>
>>
>> -- 
>> Steve Ivy
>> http://redmonk.net // http://diso-project.org
>> This email is: [ ] bloggable [x] ask first [ ] private
>> _______________________________________________
>> MTOS-dev mailing list
>> MTOS-dev at sixapart.com
>> http://www.sixapart.com/mailman/listinfo/mtos-dev
>
> _______________________________________________
> MTOS-dev mailing list
> MTOS-dev at sixapart.com
> http://www.sixapart.com/mailman/listinfo/mtos-dev



More information about the MTOS-dev mailing list