foreach

1.0 1.1 1.2 1.3

Similar to the php foreach block, loops over an array

<?php
foreach(array $from, [ string $key = null, [ string $item = null, [ string $name = 'default', [ string $implode = null ]]]])

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

Examples

Example #1

index.php
array(
  'arr' => array(
    array('id'=>1, 'name'=>'Jim'),
    array('id'=>2, 'name'=>'John'),
    array('id'=>3, 'name'=>'Bob'),
  )
)
index.tpl
{foreach $arr val implode=", "}
  {$val.id} - {$val.name}
{/foreach}

The above example will output:

 1 - Jim,
 2 - John,
 3 - Bob