{foreach:variable,key,value} – creates a PHP foreach loop


Usage ( {foreach:variable,key,value} , {foreach:variable,value} )


creates a foreach loop, needs an {end:} tag. note that the engine will add the variable to the scope, so they will not be prefixed with $t-> when used inside the loop.


  • 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

  k is {k}, and v is {v}
  v is {v}

Compiled template

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

example output

k is dog, v is cat
k is fire, v is water
v is a
v is b
v is c
creates a PHP method call, and echos the results (Previous) creates a PHP if statement (Next)
Last updated: Fri, 27 Nov 2015 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.