Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

How do i set up a counter in smarty?

 
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
sman
Smarty n00b


Joined: 22 Jan 2004
Posts: 2
Location: Melbourne, Australia

PostPosted: Thu Jan 22, 2004 6:24 am    Post subject: How do i set up a counter in smarty? Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
andre
Smarty Pro


Joined: 23 Apr 2003
Posts: 164
Location: Karlsruhe, Germany

PostPosted: Thu Jan 22, 2004 8:40 am    Post subject: Reply with quote

The "somespecialtag" is "section" Smile

Try this:
Code:
+---------------------+
{section name=i start=0 loop=$max}
        Hello number {$I}
{/section}
Back to top
View user's profile Send private message
sman
Smarty n00b


Joined: 22 Jan 2004
Posts: 2
Location: Melbourne, Australia

PostPosted: Mon Jan 26, 2004 2:03 pm    Post subject: Thanks Reply with quote

Great! thanks for the help Smile
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
PrivateeR
Smarty Rookie


Joined: 08 Dec 2004
Posts: 5

PostPosted: Sun Dec 26, 2004 5:28 am    Post subject: Reply with quote

This solved my counter prob also....
thx alot guys!
Back to top
View user's profile Send private message
deadcat
Smarty Rookie


Joined: 20 Sep 2003
Posts: 10

PostPosted: Fri Jan 14, 2005 2:58 am    Post subject: Reply with quote

me too~~ thx very much!! Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks 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