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

Smarty equivalent for PHP code

 
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 -> General
View previous topic :: View next topic  
Author Message
Psyche
Smarty Regular


Joined: 16 Apr 2006
Posts: 35

PostPosted: Tue Jan 02, 2007 1:27 pm    Post subject: Smarty equivalent for PHP code Reply with quote

Hello!

What's the equivalent of this code in Smarty?

Code:

for($i = 1; $i <= $totalPagini; $i++)
{
   if(($page) == $i)
   {
      echo "<strong> $i </strong>";
   }
   else
   {
      echo "<a href=\"vanzari.php?page=$i\"> $i </a>";
   }
}
Back to top
View user's profile Send private message
Pap
Smarty Regular


Joined: 21 Jun 2006
Posts: 69
Location: Denver, CO

PostPosted: Tue Jan 02, 2007 11:26 pm    Post subject: Reply with quote

Probably this (untested):

Code:
{section loop=$totalPagini name='page'}
{if $page == $smarty.section.page.iteration}
    <strong> {$smarty.section.page.iteration} </strong>
{else}
    <a href="vanzari.php?page={$smarty.section.page.iteration}"> {$smarty.section.page.iteration} </a>
{/if}
{/section}


Of course you need to assign $totalPagini and $page to your template.

We assign "name='page'" in the section attributes so we have access to the $smarty.section.page.iteration variable.

http://smarty.php.net/manual/en/language.function.section.php
http://smarty.php.net/manual/en/language.function.foreach.php
_________________
Don't be stupid, be a Smarty™.
Come and join the P-H-Party.
Back to top
View user's profile Send private message
Psyche
Smarty Regular


Joined: 16 Apr 2006
Posts: 35

PostPosted: Wed Jan 03, 2007 8:55 pm    Post subject: Reply with quote

I did it this way, but it doesn't number "1" as the first page. Why is that?

Code:

{foreach from=$totalPagini item=i}
   {if $smarty.get.page == $i}
      {$i}
   {else}
      {if isset($smarty.get.judet)}
         <a href="vanzari.php?judet={$smarty.get.judet}&page={$i}">{$i}</a>   
      {else}
         <a href="vanzari.php?page={$i}">{$i}</a>
      {/if}
   {/if}
{/foreach}
Back to top
View user's profile Send private message
Pap
Smarty Regular


Joined: 21 Jun 2006
Posts: 69
Location: Denver, CO

PostPosted: Thu Jan 04, 2007 8:44 pm    Post subject: Reply with quote

Is $totalPagini an array, like the "from=" value is expecting?

If it's just an integer value, then I think you need to stick with the section loop.
_________________
Don't be stupid, be a Smarty™.
Come and join the P-H-Party.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat Jan 06, 2007 1:05 am    Post subject: Reply with quote

Pap wrote:
If it's just an integer value, then I think you need to stick with the section loop.


Yes. Only {section} generates for() loops.
Back to top
View user's profile Send private message
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 -> General 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