|
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 |
Psyche Smarty Regular
Joined: 16 Apr 2006 Posts: 35
|
Posted: Tue Jan 02, 2007 1:27 pm Post subject: Smarty equivalent for PHP code |
|
|
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 |
|
Pap Smarty Regular
Joined: 21 Jun 2006 Posts: 69 Location: Denver, CO
|
Posted: Tue Jan 02, 2007 11:26 pm Post subject: |
|
|
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 |
|
Psyche Smarty Regular
Joined: 16 Apr 2006 Posts: 35
|
Posted: Wed Jan 03, 2007 8:55 pm Post subject: |
|
|
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 |
|
Pap Smarty Regular
Joined: 21 Jun 2006 Posts: 69 Location: Denver, CO
|
Posted: Thu Jan 04, 2007 8:44 pm Post subject: |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sat Jan 06, 2007 1:05 am Post subject: |
|
|
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 |
|
|
|
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
|