9. Display alternately

When the table or list is shown, striped coloring is frequently required for easy reading. To realize this, the template engine has to display two or more elements alternately. To do it, use alt attribute.

<table border="1">
  <tr var:cont="{table1}" var:alt="true" class="blue">
    <td var:cont="{name}"></td>
    <td var:cont="{author}"></td>
  </tr>
  <tr var:cont="{table1}" var:alt="true" class="red">
    <td var:cont="{name}"></td>
    <td var:cont="{author}"></td>
  </tr>
</table>
   

$tmpl = new zogan;
// snip
$model_data = array(
  'table1' => array(
    array( 'name' => 'PHP',    'author' => 'Rasmus Lerdorf' ),
    array( 'name' => 'Ruby',   'author' => 'matz' ),
    array( 'name' => 'python', 'author' => 'Guido van Rossum' )
  )
);
$tmpl->display($model_data);
   

<table border="1">
  <tr class="blue">
    <td>PHP</td>
    <td>Rasmus Lerdorf</td>
  </tr>
  <tr class="red">
    <td>Ruby</td>
    <td>matz</td>
  </tr>
  <tr class="blue">
    <td>python</td>
    <td>Guido van Rossum</td>
  </tr>
</table>
   

Successive element with the same tag name and the same value in cont attribute is possible to be displayed alternately. So

<p var:cont="{name}" var:alt="true"></p>
<span var:cont="{name}" var:alt="true"></span>
   

is not shown alternately.