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.


  • string variable - relates to $object->variable

  • string key - creates a variable 'key' in the current scope.

  • string value - optionally creates a variable 'value' in the current scope. (as in $key=>$value)


Setting variables for foreach


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

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


Foreach in template

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

Compiled template

 <?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 } ?>
 <?php if (is_array($t->b)) foreach($t->b as $v) { ?><tr>
  <td>v is <?php echo htmlspecialchars($t->v); ?></td>
 </tr><?php } ?>

Simple ouput example

k is dog, v is cat
k is fire, V is water
v is a
v is b
v is c
creates a PHP if conditional tag (Previous) Start the output, using this tag and its children. (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.