PDA

View Full Version : php in templates driving me crazy .......



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

methos
04-15-07, 11:01 AM
well, i've solved the initial problem by using $num since it is already being incremented as part of the loop, but i am still puzzled as to how to increment another variable without having it print.

Adam
04-15-07, 03:45 PM
Hey,

Use {php} {/php} instead of <?php and ?> as you would normally do in any PHP file.

From,
Adam

skshost
04-15-07, 11:10 PM
Don't feel bad, getting used to smarty takes some time.

methos
04-15-07, 11:16 PM
thanks ...

it took me a while to discover that it actually was smarty - then at least i could look up the reference ;)

I've manged to get it doing more or less what i wanted now - example of my order form at : http://tb-hosting.com/services/order.php?gid=0000000005 would appreciate any comments ...

Thanks,
Tony

Dominic
04-15-07, 11:32 PM
I have a love-hate relationship with Smarty :d

Just wish it would display errors rather than give white pages! :/