loop

1.0 1.1 1.2 1.3

Loops over an array of arrays and allows for really simple / small constructs by moving the scope down to each element automatically. It is basically a combination of foreach and with internally.

<?php
loop(array $from [, $name = "default ] )

Note that this plugin supports iterator variables through the name parameter and also supports the else plugin

Examples

Example #1

index.tpl
{loop $users}
    {$id}-{$name}
{/loop}

Data file:

index.php
<?php
'users' => array(
  array( 'id' => 1, 'name' => 'Bob'),
  array( 'id' => 2, 'name' => 'John' )
)

The above example will output:

1-Bob
2-John

Accessing the array key

To access the array key you have to use the {$_key} var within the loop, its name is not user-definable to keep this plugin as simple as possible.

Extra reads