"> Soupermail Looping Example

Looping in Templates

This page shows the use of <loop> blocks in a template.

A simple loop that counts from one to ten:
<loop name="loop1" start="1" end="10"> @loop1@ </loop>
@loop1@


The same loop, backwards:
<loop name="loop1" end="1" start="10" step="-1"> @loop1@ </loop>
@loop1@


A loop, but with a step:
<loop name="loop2" start="1" end="10" step="0.7"> @loop2@ </loop>
@loop2@


Nested loops that print a multiplication table:
<table border="1" cellpadding="3" cellspacing="0">
<loop start="1" end="10" name="y">
<tr>
<td><input type="checkbox" name="row" checked="checked" value="@y@"></td>
<loop start="1" end="10" name="x">
<td><output name="SoupermailConf" math="@x@ * @y@"></td>
</loop>
</tr>
</loop>
</table>

Notice how the values @x@ and @y@ are expanded in the loop BEFORE the <output> element is used. This means you can use the @name@ value to specify form fields that contain numbers.

looping.con"> ">

These are the rows () that you selected on the previous form. This shows how you can loop on a form field with multiple values.
<table border="1" cellpadding="3" cellspacing="0">
<loop name="y" field="row">
<tr>
<loop start="1" end="10" name="x">
<td width="10%"><output name="SoupermailConf" math="@x@ * @y@"></td>
</loop>
</tr>
</loop>
</table>

Return to the examples page.


The Soupermail configuration file that made this page looks like this:


The template that made this page is looping.txt.