Blocks:foreach

From Dwoo Docs

(Redirected from Foreach)
Jump to: navigation, search

Similar to the php foreach block, loops over an array

foreach(array $from, [ string $key = null, [ string $item = null, [ string $name = 'default', [ string $implode = null ]]]]) 
  • from : the array that you want to iterate over
  • key : variable name for the key (or for the item if item is not defined)
  • item : variable name for each item
  • name : foreach name to access it's iterator variables
  • implode : if provided, this will be added between every item

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




Example : Data is :

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

Output :

 1 - Jim,
 2 - John,
 3 - Bob
  • The implode parameter allows you to use a comma or whatever you want to use to separate your items in a much easier way than having to do {if $.foreach.name.last}, {/if} inside the foreach block for example.
Personal tools
templates
page language

French

The article you want to access doesn't exist in French.
Deutsch
The article you want to access doesn't exist in Deutsch.
Russian
The article you want to access doesn't exist in Russian.