views:

32

answers:

1

Hello Guys,

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 ;-)

+1  A: 

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
edited question. see above.
stormdrain
+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.
DRL
Heh, indeed. Noted and edited. Thanks!
stormdrain
for sure, this works, but the question was to find a way for the other notation ;-)
helle
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 `"</ul><ul>"`. So, in essence, it's not doable with the `{}` notation.
stormdrain
i see, there is no way of doing so with the desired notation ... well thanks for your help!
helle