|
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 |
sman Smarty n00b
Joined: 22 Jan 2004 Posts: 2 Location: Melbourne, Australia
|
Posted: Thu Jan 22, 2004 6:24 am Post subject: How do i set up a counter in smarty? |
|
|
Hi everyone
This is probably a really stupid question - but I was wanting to know how to set up a counter. The way I want it to work is that i pass an integer to the template - and have it count up to that number.
For example
Code: |
+---------------------+
|Sample index.php |
+---------------------+
.....
$smarty->assign('max', 3)
......
$smarty->display('index.html');
+---------------------+
|Sample index.html |
+---------------------+
{somespecialtag name=i start=0 finish=max}
Hello number {$I}
{/somespecialtag}
+-----------------+
|Sample Output |
+-----------------+
Hello number 0
Hello number 1
Hello number 2
|
--------------------------------------------------------------------------------------------------
In other words, I want to implement the following php code...
Code: |
for($i = 0; $i < $max; $i++)
{
echo "\nHello number ".$i;
}
|
Any help would be much appreciated |
|
Back to top |
|
andre Smarty Pro
Joined: 23 Apr 2003 Posts: 164 Location: Karlsruhe, Germany
|
Posted: Thu Jan 22, 2004 8:40 am Post subject: |
|
|
The "somespecialtag" is "section"
Try this:
Code: | +---------------------+
{section name=i start=0 loop=$max}
Hello number {$I}
{/section} |
|
|
Back to top |
|
sman Smarty n00b
Joined: 22 Jan 2004 Posts: 2 Location: Melbourne, Australia
|
Posted: Mon Jan 26, 2004 2:03 pm Post subject: Thanks |
|
|
Great! thanks for the help |
|
Back to top |
|
PrivateeR Smarty Rookie
Joined: 08 Dec 2004 Posts: 5
|
Posted: Sun Dec 26, 2004 5:28 am Post subject: |
|
|
This solved my counter prob also....
thx alot guys! |
|
Back to top |
|
deadcat Smarty Rookie
Joined: 20 Sep 2003 Posts: 10
|
Posted: Fri Jan 14, 2005 2:58 am Post subject: |
|
|
me too~~ thx very much!! |
|
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
|