0

i'm new with Codeigniter,and whish to know if i can access any kind of iterator for the foreach with {}-Notation in my views.

The thing is, i'm having a list which should be devided after each x items.

example (what i would like to do:

<ul>
{list}
    <li>{items}</li>
    <? if ($iterator % 15 == 0) echo "</ul><ul>"; ?>
{/list}
</ul>

thanks in advice ;-)

helle
  • 11,183
  • 9
  • 56
  • 83

1 Answers1

1

If you are using codeigniters template parser class, I don't think there is a way to do what you're looking for.

You could forego the template parser, and use a regular for loop:

<ul>
<?php
$i=1;
foreach($item as $key=>$value){
    echo "<li>".$value."</li>";
    if($i % 15 === 0) echo "</ul><ul>";
    $i++;
}
?>
</ul>
stormdrain
  • 7,915
  • 4
  • 37
  • 76
  • 1
    +1 the only way i can see is to use an additional counter as stromdrain has done, though i might possibly initialise it to 1 to begin with. – Bella Jun 18 '10 at 22:41
  • for sure, this works, but the question was to find a way for the other notation ;-) – helle Jun 19 '10 at 10:37
  • 1
    I suppose you could modify the template parser class, but then all of your lists (or anything else run through the class) will have the `"
      "`. So, in essence, it's not doable with the `{}` notation.
    – stormdrain Jun 19 '10 at 15:38
  • i see, there is no way of doing so with the desired notation ... well thanks for your help! – helle Jun 21 '10 at 12:23