Search code examples
codeigniternotation

is there an index to be accessed in the CI foreach with {}-Notation?


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


Solution

  • 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>