<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Sigma example 2: block iteration</title> </head> <body> <h1>Σ<sub>template</sub> example 2: block iteration</h1> <h2>1. Simple block iteration</h2> <p>Basic <b>parse()</b> example. Filling a list from an array.</p> <!-- BEGIN list_block --> <ul> <!-- BEGIN list --> <li>{list_item}</li> <!-- END list --> </ul> <!-- END list_block --> <h2>2. Nested block iteration</h2> <p>Let's fill a HTML table from a two-dimensional array.</p> <table border="1"> <!-- BEGIN table_row --> <tr> <!-- BEGIN table_cell --> <td>{table_item}</td> <!-- END table_cell --> </tr> <!-- END table_row --> </table> <h2>3. Menu-like structures</h2> <p>This is used to output a sequence of elements that may have different presentation, consider things like normal and selected elements in menu. The much more complex example is the ITDynamic renderer of HTML_QuickForm.</p> <ul> <!-- BEGIN menu --> <!-- BEGIN menu_normal --> <li><a href="#{menu_url}">{menu_title}</a></li> <!-- END menu_normal --> <!-- BEGIN menu_selected --> <li><b>{menu_title} (you are here)</b></li> <!-- END menu_selected --> <!-- END menu --> </ul> <h2>4. Methods to manually control removal of blocks</h2> <p><b>touchBlock()</b> is used to show the blocks that would be considered empty and therefore will be removed.</p> <table border="1"> <!-- BEGIN touch_row --> <tr> <!-- BEGIN touch_cell --> <td>{touch_stuff}</td> <td>{touch_quantity}</td> <!-- END touch_cell --> <!-- BEGIN empty_row --> <td colspan="2">This row is intentionally left blank (and thus should be removed)</td> <!-- END empty_row --> </tr> <!-- END touch_row --> </table> <p><b>hideBlock()</b> is used to hide the blocks that would be shown due to their non-empty status, in this case 'edit' links.</p> <ul> <!-- BEGIN hide_item --> <li>{item_title} <!-- BEGIN edit_link --><a href="?edit={item_id}">edit</a><!-- END edit_link --></li> <!-- END hide_item --> </ul> <h2>5. Using get() to move blocks around</h2> <p>If you need a copy of a block somewhere else in the template...</p> <p>This is a copy of the block from section 1:</p> {duplicate} </body> </html>