I need a little help with the smarty templating engine.

See, I know to loop through an array you use the {section} command and even the {cycle} if you want to do things like change the bg color for each row...

However, what I'm trying to do is do a double-cycle like thing, if you can call it that.

I want to loop through an array, displaying the info into a table, but I want to display 3 array items PER row and THEN switch to the next row..

So for example the table should look like this after it is outputted:

Item 1 Item 2 Item 3
Item 4 Item 5 Item 6
Item 7 Item 8 Item 9

and so on. Does anyone have any suggestions or websites I can go to that'll tell me how to do this?

Thanks!

    use php to split the 9 items into a multidimensional array of rows

    $row[0] = array ("item1", "item2", "item3");
    $row[1] = array ("item4", "item5", "item6");
    $row[2] = array ("item7", "item8", "item9");

    and then put two {section} bits in the template, nested

      It appears so.. but it can't do if-else statements because that's application logic... I think at least. If it can please correct me.

      Thanks

        {if ($entries[entry].index_prev % 3 == 0) && ($entries[entry].index_prev > 0)}
        </tr><tr>
        {/if}

        something like this might work

          Hey thanks a lot. Maybe I should have searched the smarty site before posting on this forum. It's probably blatantly obvious that I've never actually used smarty before.. sad since I've been using PHP for so many years..

            Write a Reply...