flexy:foreach="variable,key,value"

flexy:foreach="variable,key,value" -- creates a PHP foreach loop using a html attribute

概要

Usage (flexy:foreach="variable,key,value", flexy:foreach="variable,value")

説明

creates a foreach loop, around the tag and close tag.

パラメータ

例 40-1Setting variables for foreach

$this->a = array(
  "dog" => "cat",
  "fire" => "water"
);

$this->b = array('a','b','c');

$template->outputObject($this);

例 40-2Foreach in template

<table>
  <tr flexy:foreach="a,k,v">
    <td>k is {k}, and v is {v}</td>
  </tr>
</table>
<table>
  <tr flexy:foreach="b,v">
    <td>v is {v}</td>
  </tr>
</table>

例 40-3Compiled template

<table>      
 <?php if (is_array($t->a)) foreach($t->a as $k => $v) { ?><tr>
  <td>k is <?php echo htmlspecialchars($t->k); ?>, and v is <?php echo htmlspecialchars($t->v); ?></td>
 </tr><?php } ?>
</table>
<table>      
 <?php if (is_array($t->b)) foreach($t->b as $v) { ?><tr>
  <td>v is <?php echo htmlspecialchars($t->v); ?></td>
 </tr><?php } ?>
</table>

例 40-4Simple ouput example

k is dog, v is cat
k is fire, V is water
  
v is a
v is b
v is c