 |
Smarty
The discussions here are for Smarty, a template engine for the PHP programming language. Dedicated server web hosting provided by Guru-host.eu. |
| View previous topic :: View next topic |
| Author |
Message |
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7038 Location: Lincoln Nebraska, USA
|
Posted: Mon Feb 08, 2010 6:43 pm Post subject: Smarty 3: {for} tag |
|
|
Smarty 3 now has an incredibly useful {for} tag for easy looping with a simple, clean syntax. Example, looping 5 times:
| Code: | {for $x = 1 to 5}
{$x}
{/for} |
output:
1
2
3
4
5
Here is another example stepping by 2:
| Code: | {for $x = 1 to 10 step 2}
{$x}
{/for} |
output:
1
3
5
7
9
You can also use any valid expressions:
| Code: | {for $x = abs($min-1) to count($foo)}
...
{/for} |
Inside the loop the following special vars can be accessed:
| Code: | $x@iteration = number of iteration
$x@total = total number of iterations
$x@first = true on first iteration
$x@last = true on last iteration
|
Last edited by mohrt on Thu Mar 17, 2011 6:48 pm; edited 3 times in total |
|
| Back to top |
|
SoN9ne Smarty Rookie

Joined: 25 Feb 2010 Posts: 17
|
Posted: Fri Mar 26, 2010 2:54 pm Post subject: |
|
|
Thanks! Just what I needed.  |
|
| 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
|