Re: enhanced foreach loops

"Miguel Simões" <[email protected]> Thu, 16 Nov 2006 19:03:22 +0000
Newsgroups gmane.comp.php.smarty.devel
Message-ID <[email protected]>
I have to agree with Ken, its a interesting idea and also a very useful one
since it will allow to remove some redundant cycles/assigns to obtain that
value.

On the issue of the value, I guess the logical one would be NULL (since its
not assigned/existent) or optional, which I don't like but possible, to
break cycle if one of elements don't exist.


Greets,
Miguel Simões

On 11/16/06, Ken Snyder <[email protected]> wrote:
>
> Very interesting idea... You could do {assign var=previous_call
> value=$message.backtrace[$smarty.foreach.backtrace.index + 1]} but it
> wouldn't work for associative arrays or objects.  I like it!  What would
> be the desired behavior of $smarty.foreach.NAME.next when on the last
> item?  A default value? NULL?
>
> --Ken
>
> Kerry Wilson wrote:
> > I would like to enhance the foreach loop by adding next and previous
> > to the foreach variables.
> >
> > Example usage:
> >
> > {foreach from=$message.backtrace item='call' name='backtrace'}
> >  {assign var='previous_call' value=|$smarty.foreach.backtrace.next}|
> >  <li style='list-style: none;'>{$call.file} [{$call.line}] -
> > {$previous_call.class}.{$previous_call.function}(){/if}</li>
> > {/foreach}
> >
> > In case you cannot tell I am using this to print a backtrace ( I want
> > it to show the method it is currently in, not the one that it is
> > calling ).
> >
> > Where does the foreach implementation reside in source?  And is this a
> > good thing to add to the base code?
> >
>
> --
> Smarty Development Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>