Sluz v0.9.4 documentation

Available documentation:

031_advanced_foreach.php

PHP:
<?php

///////////////////////////////////////////////////////////////////////////////
// {foreach} blocks apply special variables on each loop interation. They    //
// are: $__FOREACH_FIRST, $__FOREACH_LAST, $__FOREACH_INDEX. First/Last will //
// be true if it is either first of last interation, and the index will be   //
// set the loop iteration number (starting at zero).                         //
///////////////////////////////////////////////////////////////////////////////

include("../sluz.class.php");
$s = new sluz();

$s->assign("turtles", ["Michelangelo", "Donatello", "Leonardo", "Raphael"]); // Array

print $s->fetch("tpls/031_advanced_foreach.stpl");
Template:
<p>
{foreach $turtles as $name}
<div style="background: {if $__FOREACH_FIRST}orange{elseif $__FOREACH_LAST}red{else}yellow{/if}">{$name}</div>
{/foreach}
</p>

<p>
{foreach $turtles as $name}
<div>{$__FOREACH_INDEX}) {$name}</div>
{/foreach}
</p>