methos
04-15-07, 10:14 AM
Hi all,
I am having a headache here whilst trying to create a customised order form template.
I used to be halfway proficient a php a few years back, but I have never come across this style of code within curly braces that is used in the templates and trying to get it to do what i want is driving me crazy.
I am trying to increment a counter variable within the main loop of the first order form template and the code snippet i am using is shown below. My problem is that everytime I increment the value of $cnt (using $cnt++) it actually prints the value of $cnt to the html output - what the heck am i doing wrong?
here is a simplified version of the code (the output extra columns are simply there so i can test the value of $cnt whilst building it) - the first time through the loop it is fine and creates my extra column and tells me $cnt eq 1, but then every other time through it not only does that but echo's the value before incremnting back to the actual html output. How can I stop this echo?
{$cnt = 0}
{foreach key=num item=product from=$products}
<table width="98%">
<tr>
<td >
<form method="post" action="{$smarty.server.PHP_SELF}?step=2">
<input type="hidden" name="pid" value="{$product.pid}">
{$product.name}
{$product.description}
<input type="hidden" name="billingcycle" value="monthly">
<input type="submit" value="{$LANG.ordernowbutton}">
{ $cnt++ }
</form>
</td>
{if $cnt eq 1} <td>extra column after 1</td> {/if}
{if $cnt eq 2} <td>extra column after 2</td> {/if}
{if $cnt eq 3} <td>extra column after 3</td> {/if}
{if $cnt eq 4} <td>extra column after 4</td> {/if}
{if $cnt eq 5} <td>extra column after 5</td> {/if}
</tr>
</table>
{/foreach}
thanks,
Tony
I am having a headache here whilst trying to create a customised order form template.
I used to be halfway proficient a php a few years back, but I have never come across this style of code within curly braces that is used in the templates and trying to get it to do what i want is driving me crazy.
I am trying to increment a counter variable within the main loop of the first order form template and the code snippet i am using is shown below. My problem is that everytime I increment the value of $cnt (using $cnt++) it actually prints the value of $cnt to the html output - what the heck am i doing wrong?
here is a simplified version of the code (the output extra columns are simply there so i can test the value of $cnt whilst building it) - the first time through the loop it is fine and creates my extra column and tells me $cnt eq 1, but then every other time through it not only does that but echo's the value before incremnting back to the actual html output. How can I stop this echo?
{$cnt = 0}
{foreach key=num item=product from=$products}
<table width="98%">
<tr>
<td >
<form method="post" action="{$smarty.server.PHP_SELF}?step=2">
<input type="hidden" name="pid" value="{$product.pid}">
{$product.name}
{$product.description}
<input type="hidden" name="billingcycle" value="monthly">
<input type="submit" value="{$LANG.ordernowbutton}">
{ $cnt++ }
</form>
</td>
{if $cnt eq 1} <td>extra column after 1</td> {/if}
{if $cnt eq 2} <td>extra column after 2</td> {/if}
{if $cnt eq 3} <td>extra column after 3</td> {/if}
{if $cnt eq 4} <td>extra column after 4</td> {/if}
{if $cnt eq 5} <td>extra column after 5</td> {/if}
</tr>
</table>
{/foreach}
thanks,
Tony