|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
jarofgreen Smarty Rookie
Joined: 09 Jul 2010 Posts: 14
|
Posted: Fri Sep 24, 2010 9:43 am Post subject: A while loop that assigns values until null |
|
|
I'm looking for a plug-in for Smarty 3 that does a while loop like the PHP code:
Code: | while($x = $y->getNextResult()) {
...
} |
So it loops round until getNextResult() starts to return Null.
It would look something like this:
Code: | {whileassign from=$y->getNextResult() var=x}
... {$x} ...
{/whileassign} |
Ideally, it would also assign counters to the smarty global like for does, so you can have
Code: | {whileassign from=$y->getNextResult() var=x name=foo}
... {$x} ... {$smarty.while.foo.index} ...
{/whileassign} |
Or at the very least:
Code: | {whileassign from=$y->getNextResult() var=x counter=count}
... {$x} ... {$count} ...
{/whileassign} |
Does anyone have such a thing, or can anyone point me to something similar I can use as guidance to write one myself? I'll release it under the BSD licence as part of Elastik (which you can find on SourceForge)
Thanks very much,
James |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Sep 24, 2010 12:54 pm Post subject: |
|
|
This is already build in (not yet documented)
Code: | {while $x=$y->getNextResult()}
... {$x} ...
{/while} |
or
Code: | {while $x>0}
.... {$x=$x-1}....
{/while} |
The {while} tag can be used with an assignment as in the first example or an if-condition like in the second example. |
|
Back to top |
|
jarofgreen Smarty Rookie
Joined: 09 Jul 2010 Posts: 14
|
Posted: Fri Sep 24, 2010 1:30 pm Post subject: |
|
|
Cool, that's fantastic! And I have just realised I can use Cycle to do what I want so I don't need to get a count out of it.
Thanks for your prompt reply |
|
Back to top |
|
|
|
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
|