A Pizza price list. Data:
$columns = array('Pizza','Price');
$data = array(array('Pepperoni','7.99'),array('Veggie','6.99'));
Template for price list:
<!-- cut:table -->
<table>
<thead>
<tr>
<!-- paste:columns(column,data) -->
<!-- cut:column -->
<th>#column#</th>
<!-- /cut:column -->
</tr>
</thead>
<tbody>
<!-- paste:rows -->
<!-- cut:row -->
<tr>
<!-- paste:cells -->
<!-- cut:cell -->
<td>#cell#</td>
<!-- /cut:cell -->
</tr>
<!-- /cut:row -->
</tbody>
</table>
<!-- /cut:table -->
Presentation logic:
$se = new StampTE($template);
list($table,$columnHead,$row,$cell) =
$se->collect('table|table.column|table.row|table.row.cell');
foreach($columns as $column)
$table->glue('columns',$columnHead
->copy()
->inject('column',$column));
foreach($data as $pizzaInfoLine) {
$pizzaRow = $row->copy();
foreach($pizzaInfoLine as $pizzaInfo) {
$pizzaRow->glue('cells',$cell->copy()->inject('cell',$pizzaInfo));
}
$table->glue('rows',$pizzaRow);
}
echo $table;
And here is what you get:
<table>
<thead>
<tr>
<th>Pizza</th><th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Pepperoni</td><td>7.99</td>
</tr><tr>
<td>Veggie</td><td>6.99</td>
</tr>
</tbody>
</table>
That's the menu for today! While it may seem that the markers cause overhead in your template this is mostly because the examples here are oversimplified. Most templates are far more complex and the additional overhead of the markers will be relatively small.