|
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 |
Pierre-Henri Smarty Rookie
Joined: 09 Nov 2010 Posts: 5
|
Posted: Tue Nov 09, 2010 4:07 pm Post subject: Modulo in my foreach |
|
|
Hello everybody,
In first, please excuse me for my english. I'm french
I'm currently using Smarty to display an array content.
I want to display a portion of HTML each 6 items for create a pagination.
I think the best way is to use modulo by 6 but it doesn't work.
For example, I want this result (The <br/> is writed every 6 items)
Code: | <div class="items">item 1</div>
<div class="items">item 1</div>
<div class="items">item 2</div>
<div class="items">item 3</div>
<div class="items">item 4</div>
<div class="items">item 5</div>
<br/>
<div class="items">item 6</div>
<div class="items">item 7</div>
<div class="items">item 8</div>
<div class="items">item 9</div>
<div class="items">item 10</div>
<div class="items">item 11</div>
<br/>
<div class="items">item 12</div>
<div class="items">item 13</div> |
Do you understand my request ?
Thanks forward for your help !
pH |
|
Back to top |
|
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Tue Nov 09, 2010 7:19 pm Post subject: straight forward solution |
|
|
Here is a straight forward solution to this:
Template file:
Code: | {section name='i' loop=$items}
<div class="items"><a href="{$items[i].1}">{$items[i].0}</a></div>
{if $smarty.section.i.index_next%7==6}
<br />
{/if}
{/section} |
Assigned PHP variable, $item is like:
Code: | $items = array(
array('item 1', '1.php'),
array('item 2', '2.php'),
array('item 3', '3.php'),
array('item 4', '4.php'),
array('item 5', '5.php'),
array('item 6', '6.php'),
array('item 7', '7.php'),
array('item 8', '8.php'),
array('item 9', '9.php'),
array('item 10', '10.php'),
array('item 11', '11.php'),
array('item 12', '12.php'),
array('item 13', '13.php'),
array('item 14', '14.php'),
array('item 15', '15.php'),
);
$smarty->assign('items', $items); |
Just guess, why there is a need to use $number%7==6 ...
Output is:
Code: | <div class="items"><a href="1.php">item 1</a></div>
<div class="items"><a href="2.php">item 2</a></div>
<div class="items"><a href="3.php">item 3</a></div>
<div class="items"><a href="4.php">item 4</a></div>
<div class="items"><a href="5.php">item 5</a></div>
<div class="items"><a href="6.php">item 6</a></div>
<br />
<div class="items"><a href="7.php">item 7</a></div>
<div class="items"><a href="8.php">item 8</a></div>
<div class="items"><a href="9.php">item 9</a></div>
<div class="items"><a href="10.php">item 10</a></div>
<div class="items"><a href="11.php">item 11</a></div>
<div class="items"><a href="12.php">item 12</a></div>
<div class="items"><a href="13.php">item 13</a></div>
<br />
<div class="items"><a href="14.php">item 14</a></div>
<div class="items"><a href="15.php">item 15</a></div> |
|
|
Back to top |
|
Pierre-Henri Smarty Rookie
Joined: 09 Nov 2010 Posts: 5
|
Posted: Wed Nov 10, 2010 4:33 pm Post subject: |
|
|
Hi,
Thank you for reply me.
I've tried your solution and it solve my problem !
Thanks a lot !
Bye.
pH |
|
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
|