Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

First/Last values for {foreach}

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
h1nebefe
Smarty Rookie


Joined: 20 Apr 2003
Posts: 7

PostPosted: Sun Apr 20, 2003 4:58 pm    Post subject: First/Last values for {foreach} Reply with quote

If it exists already please tell me Embarassed

DocUK
Back to top
View user's profile Send private message Send e-mail
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sun Apr 20, 2003 5:39 pm    Post subject: Reply with quote

you don't have the actual first and last values, but you have boolean-values to indicate wether the current iteration is the first or the last (or both Smile ) . it this what you need ?

Code:

{foreach name=foo from=$array}
{if $smarty.foreach.foo.first} do something {/if}

{$smarty.foreach.foo|@debug_print_var} // show what else is known for this foreach

{if $smarty.foreach.foo.last}  do something {/if}
{/foreach}


HTH
messju
Back to top
View user's profile Send private message Send e-mail Visit poster's website
h1nebefe
Smarty Rookie


Joined: 20 Apr 2003
Posts: 7

PostPosted: Sun Apr 20, 2003 6:12 pm    Post subject: Reply with quote

That's what I meant! Thanks!
Back to top
View user's profile Send private message Send e-mail
guido
Smarty Rookie


Joined: 02 May 2003
Posts: 9

PostPosted: Tue Jul 15, 2003 1:05 am    Post subject: Reply with quote

messju, since this isn't documented anywhere ..

what values work for foreach? compared to section..

I tried rownum and it didn't work in the foreach.. a list would be great.
_________________
read docs .. read 'em .. uh oh i'm dumb
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Jul 15, 2003 7:24 am    Post subject: Reply with quote

it is documented in the cvs-version of the docs. the docs on the smarty website will be updated with the next stable release of smarty (dunno when)


(from the docs)
iteration
iteration is used to display the current loop iteration.
Iteration always starts with 1 and is incremented by one one each iteration.

first
first is set to true if the current foreach iteration is the first one.

last
last is set to true if the current foreach iteration is the last one.

show
show is used as a parameter to foreach. show is a boolean value, true or false. If false, the foreach will not be displayed. If there is a foreachelse present, that will be alternately displayed.

total
total is used to display the number of iterations that this foreach will loop. This can be used inside or after the foreach.

HTH
messju
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP